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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.