• Javascript function parameter quotes, do I add them or not?
    5 replies, posted
Hey, got problem here: basically I have this code in HTML: [code] <input type="text" value="Username" name="forms_login_username" id="forms_login_username" onfocus="ClearField(forms_login_username)" onblur="ClearField(forms_login_username)"/>[/code] and in javascript file I have: [code] function ClearField(var FieldName){ var field = document.getElementById(FieldName); if(field.value == field.defaultValue){ field.value = ""; } else if(field.value.length < 1){ field.value = field.defaultValue; } } [/code] But it doesn't work, if I specify elementId in function then it works on click, but I have like 7 fields and I don't want to copy/paste same function 7 times with changing their ElementId's, I tried making it so it's same function name but I specify field name in parameters but that didn't work. Help? Btw it's supposed to remove value from field on click, and if user didn't enter anything return it to default value.
Use the html5 placeholder attribute and a js shim to support it for older browsers instead.
[QUOTE=KmartSqrl;36332977]Use the html5 placeholder attribute and a js shim to support it for older browsers instead.[/QUOTE] Please explain what do you mean by that? I don't know really I am just beginner at javascript.
I don't want to be the "just google it" guy but if you're interested in development you need to teach yourself how to teach yourself. try "html5 placeholder attribute" and "javascript shim html5 placeholder" and I can guarantee you'll find all the info you need.
alright thanks [editline]15th June 2012[/editline] oh I see now, guess I don't need Javascript for this thing then
Generally the javascript is just to enable older browsers that don't yet support the placeholder attribute to still use it. There's a lot of jquery plugins out there that are pretty much just plug and play for that though.
Sorry, you need to Log In to post a reply to this thread.