When using
forms within your web site, there may be times when you will want to include
an example of what you'd like your visitors to fill in your form field. Although
you could place some default text within your form field, your users would
need to delete the default text in order to type in their own information.
However, this cool little JavaScript code will enable you to display some
example default text within a text box that will disappear when clicked on
- much better than your users having to delete the example
text.
Example:
Place the following
code between your <HEAD> and </HEAD> tags:
<script
language=JavaScript>
<!-- Script courtesy of http://www.web-source.net - Your Guide to Professional
Web Site Design and Development
function clear_textbox()
{
if (document.form1.text1.value == "Enter Your Default Text Here")
document.form1.text1.value = "";
}
-->
</script> |
Place your form code within your HTML like this:
<form
name="form1"
action="http://www.yourwebaddress.com/form.cgi"
method=post>
<input name=text1 onFocus=clear_textbox() value="Enter Your Default
Text Here">
<input type=submit value=Submit>
</form> |
Change the web
address indicated in red to your form address.
If you'd like to change the default text displayed within your text box,
make sure you change it in both the JavaScript code and your form code as
indicated in bold.
Script code provided by:
Ryan Hagfors |