hi, i have this in my form: <input type="text" value="Enter Keywords" onfocus="if(this.value=='Enter Keywords'){this.value='';}" /> HTML: and it works great, but how can i add to it to so that if the form is empty or default text (i.e. "Enter Keywords"), then no action is taken (i.e. cannot submit) or maybe just to make it reload page? cheers
A simple example to do it: <html> <head> <title>Enter Keywords</title> </head> <body> <form name="enter_keywords_form" id="enter_keywords_form" method="post"> <input id="enter_keywords" type="text" value="Enter Keywords" onfocus="if(this.value=='Enter Keywords'){this.value='';}" onblur="if(this.value==''){this.value='Enter Keywords';}" /> <input type="button" value="Submit" onclick="if(document.getElementById('enter_keywords').value!='' && document.getElementById('enter_keywords').value!='Enter Keywords'){ document.enter_keywords_form.submit(); }"> </form> </body> </html> Code (markup):
if the field is left blank or "Enter Keywords", then i do not want the form to be submited. how would i change the following please? thanks again!
remove that onClick stuff from the button and put this in the form tag: onSubmit="if(document.getElementById('enter_keywords').value=='' || document.getElementById('enter_keywords').value=='Enter Keywords'){ return false; }" Code (markup):
Here is the code you want: <html> <head> <title>Enter Keywords</title> </head> <body> <form name="enter_keywords_form" id="enter_keywords_form" method="post"> <input id="enter_keywords" type="text" value="Enter Keywords" onfocus="if(this.value=='Enter Keywords'){this.value='';}" onblur="if(this.value==''){this.value='Enter Keywords';}" /> <input type="button" value="Submit" onclick="if(document.getElementById('enter_keywords').value!='' && document.getElementById('enter_keywords').value!='Enter Keywords'){ document.enter_keywords_form.submit(); }"> </form> </body> </html> Code (markup): What doesn't work?
ah, great stuff, all sorted now! thanks noticed on IE that it still lets you submit the form if you hit enter instead of the button, but that's just because IE sucks?