|
|
|||||||
|
I am new to this forum and asp. I did read a earlier thread which helped me ---I want to clear a textbox when the user clicks on it--I am putting a default value in it but if they want to enter a value I want the textbox to clear when they click it. The solution I saw in this forum was: <html> <head> <script language="javascript"> function cleartext() { document.form1.textbox.value = "" } </script> </head> <body> <form name="form1"> <input type="text" value="Enter Keywords here..." onclick="cleartext()"> </form> </body> </html> When I use this and run it --and then click on a textbox field I get a message at the bottom of the browser "error on page". Now this script is running in iis. I also tried changing the script to VBscript. Does anyone know why I am getting this error?? THANKS! |
||||||||
|
|
|||||||
|
Don't know why you are getting the error but you can use this code instead: <form name="form1"> <input type="text" value="Enter Keywords here..." onFocus="value=''"> </form> To see an example of this see www.bains007.co.uk (my site; it's on the Google search box)
|
||||||||
|
|
|||||||
|
THANKS! That worked---not quite like I want but it will do! I really appreciate the help!! SMILES! |
||||||||
|
|
|||||||
|
No probs, what was it you wanted to do? ![]() http://www.bains007.co.uk |
||||||||
|
|
|||||||
|
nanook - the problem with your code is that it clears the text box EVERY time the user clicks on it. My code will only clear the text box if the text in the box is the same as your default text. <html> <head> <title> </title> <script> function clearText() { if (document.myForm.keyword.value == document.myForm.defaultText.value) { document.myForm.keyword.value = "" ; } } </script> </head> <body align="center"> <form name="myForm"> <input type="text" name="keyword" value="Enter keyword here..." onClick="JavaScript: clearText()"> <input type="hidden" name="defaultText" value="Enter keyword here..."> </form> </body> </html> |
||||||||
|
|
|||||||
|
Sorry, hadn't quite read the script correctly, don't know how to do what you want, search Google and there are lots of results ![]() http://www.bains007.co.uk |
||||||||
|
|
|||||||
|
Tried that code, but it doesn't seem to like existing forms, with different names. |
||||||||
|
|
|||||||
|
Change the names then! |
||||||||
|
|
|||||||
|
I've changed the names in the bit in <head> section of code, but it still doesn't work. I can't change my forms' names to MyForm either, as there are two different forms on one page, with different names. |
||||||||
|
|
|||||||
|
OK, try this badboy. <html> <head> <title> </title> <script> function clearText(textElement, defaultElement) { if (textElement.value == defaultElement.value) { textElement.value = "" ; } } </script> </head> <body align="center"> <form name="myForm"> <input type="text" name="keyword" value="Enter keyword here..." onClick="JavaScript: clearText(this, document.myForm.defaultText);"> <input type="hidden" name="defaultText" value="Enter keyword here..."> </form> </body> </html> The only think you'll need to change is the document.myForm.defaultText so that it points to the hidden element in your form that holds the default text. Therefore, if your form name is MattsForm and the hidden element in the form that holds the default text is called MattsDefaultText you'll need to change the line to: document.MattsForm.MattsDefaultText |