Jump to content

on focus and restore for form


jasonc

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/170565-on-focus-and-restore-for-form/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.