tags:

views:

67

answers:

3
A: 

I think you want line 7:

$(this).isFocused == "false";

to be

$(this).isFocused = "false";
umop
Yes, you are absolutely correct on that, however that's not going to be what the overall problem is.
Thomas McCabe
You'll also want to use the keywords `true` and `false` instead of the string values that you have.
umop
With PHP I'm used to the string values (or for me, I prefer 0's and 1's). Tried that as well to no avail, but good to know they are actually key words.
Thomas McCabe
A: 

I think the following would probably evaluate the same in this instance, but shouldnt:

if ($(this).hasfocus == "true") return;

be:

if ($(this).hasfocus == true) return;

prodigitalson
A: 

You might want to refactor a bit.

Create named functions, or [better]create an object (global is ok if You don't have a lot of js out there) and put Your functions in that object so that they have names.

MyAwesomeGlobalSomething={};
MyAwesomeGlobalSomething.mOverFunc=function(){
  //the stuff You do
       if ($(this).hasfocus == true) return;
            else {
                var text = getAttr($(this));
                $(this).removeClass();
                if($(this).attr("value") == text) $(this).addClass('inputOver clear');
                else $(this).addClass('inputOver filled');
            }
}
//and more functions here

You can now bind

 $('.input').mouseover(MyAwesomeGlobalSomething.mOverFunc);

now

$('.input').focus(function(){
  $(this).unbind('mouseover');
//and more functions here
});

fixes Your problem and

$('.input').blur(function(){
  $(this).mouseover(MyAwesomeGlobalSomething.mOverFunc);
//and more functions here
});

returns the function binding

naugtur
I'm going to give this a whirl. Nice description. Being that JS isn't a true OO language, JS objects have tripped me up so far. The Flanagan book doesn't do too great of a job explaning it but this might get me going down the right road. I was planning on making all of this a plugin (using CSS3 gradients rather than the images). How would using objects work in that case, and what is the alternative to global objects considering this will eventually be used in many different instances?
Thomas McCabe
JS is based on Prototyping idea. You can inherit from objects not classes and add methods on the fly - that's the basic of basics of that concept. If you are creating a plugin I'd recommend putting the object in jquery.pluginname namespace. Read about plugin authoring and It's there somewhere. Feel free to ask if not satisfied ;) I enjoy introducing people representing ambitious approach
naugtur
Hey naugtur, here's what I've come up with (which works fine so far! also have moved to CSS3 properties rather than images [interestingly enough I had to force border color changes by .css(). Weird!]): http://jsfiddle.net/uVDQP/3 -- Now, I'd like to refactor this a little further before I build it into a plugin. I tried (and failed), but I'd like to make the TextInput object (and in turn the subsequent objects that will handle the other form field types) into a constructor object with all the stuff going on in the jQuery "each" statement happening automatically with the "new" instantiation.
Thomas McCabe
As interesting as it sounds (moreover - I did some OO-style things in JS+jQuery) I'd recommend creating an `unobtrusive` plugin that would transform a simple input into this cool looking one with such a code: `$('.myinput').makeItLookAwesome();` Start the plugin from this template: http://docs.jquery.com/Plugins/Authoring#Putting_It_All_Together
naugtur
I did a mockup (not correct code yet, boot it's how it should look) http://jsfiddle.net/dtFq4/2/
naugtur