Once I get this working, I intend to package it and post it for you guys. But I need a little help.
I'm trying to write a small script to have form prompts, like the more professional sites use. An example is:
(imagine this line in a form field)
Your Name_____
Click on the box, and it just shows:
______________
So it deletes the input value to make room for what you type. Most importantly, it must not delete what the user puts in there if they blur then re-click on the field.
Also, I tried to make it so that each element stores its initial value as a global property, instead of making it a variable in the function; so that each individual form field would remember its individual prompt.
The script I've written looks like this:
function irs_prompt(element,action) {
if (element.init_value_set==="") {
element.init_value_set=1;
if (element.init_value==="") {
element.init_value=element.value;
}
}
if (action == "click") {
if (element.value == element.init_value) {
element.value = "";
}
}
if (action == "blur") {
if (element.value === "") {
element.value = element.init_value;
}
}
}
And it does nothing at all. I've been scratching my head over this; I've got the parameters of the form object set correctly, i.e. function name equals script name, and the 'click' and 'blur' checkboxes are checked (I'm using the sample contact form name field to test, and I've removed the 'get focus' initial script) so I have to be failing in my javascript somehow. However, I'm no scripting guru, so I just can't see what I'm doing wrong right now. Does anybody else see what's failing here?