jasonc Posted August 16, 2009 Share Posted August 16, 2009 I wish to have a form clear the default text from my form and allow the user to type in the field but if they move to another fields and do not enter anything in that fields they first went in to the fields restores to the default tetx that was in there before. i have name: tel: state: in the fields by default. i have heard this should be done using javascript can someone help me out here with some coding. i have tried to find it but only find ones that use on focus and for only one fields not multiple Quote Link to comment Share on other sites More sharing options...
haku Posted August 17, 2009 Share Posted August 17, 2009 Show us the code you have written so far. Quote Link to comment Share on other sites More sharing options...
jasonc Posted August 17, 2009 Author Share Posted August 17, 2009 it is the very early stages of this side of the site... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form name="form1" method="post" action=""> <input name="name" type="text" id="name" value="Name: "> <br> <br> <input name="email" type="text" id="email" value="Email: "> <br> <br> <textarea name="message" id="message">message: </textarea> <br><br> <input name="submit" type="submit" value="Submit"> <input name="" type="reset"> </form> </body> </html> i would like the default text to be in the fields if and if the fields are empty not have data entered by the user. also if they clear the form the defaults come back. Quote Link to comment Share on other sites More sharing options...
haku Posted August 18, 2009 Share Posted August 18, 2009 You need to use onfocus and onblur. When the user clicks into the field, you use onblur, and check the value in the field. If it is the default value, then you clear the value. If it is anything else (i.e. the user has entered something), then you leave it as is. You do the opposite using onblur (which happens when the user leaves the input. If the value of the input is blank, you add the default text. If it's anything else, you leave it as is. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.