PDA

View Full Version : Problem with form input reset.



perfectheat
Apr 13th, 2010, 01:32 PM
Hello. I have a problem with a form and it's predefined input values.

The problem is that when I write something in a field and, goes on to the next field, but then goes back to any filled in fields it just resets it to the predefined value. It's the same with the text area.



<form action="send-email.php" method="post" id="contact-form">
<input name="name" id="fname" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'Name':this.value;" value="Name" type="text">
<input name="email" id="email" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'E-mail':this.value;" value="E-mail" type="text">
<textarea name="details" id="details" rows="20" cols="40" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'Query':this.value;" value="Query">Query</textarea>

<input onclick="sendEmail()" value="" class="button" type="button">
</form>


Thank you for looking at my messy code. I'm very new to this.

Regards,
M.

Kor
Apr 13th, 2010, 03:21 PM
Well, you should have explained us first what you intend to do, and afterward what it the real result.

So: what is your aim?

perfectheat
Apr 13th, 2010, 03:40 PM
Sorry, thought I was clear.

I don't want it to delete the content of a field that has been filled in. Now if I want to change something in any of the fields or textarea I have to start over as the filled in information is deleted in the field I select.

tomws
Apr 13th, 2010, 03:58 PM
Here's the problem:

onclick="this.value='';"
You're deleting it whenever the input is clicked. Notice that the values don't change when tabbed.

Kor
Apr 13th, 2010, 04:00 PM
Like this?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function Focus(obj){
obj.value==obj.defaultValue?obj.value='':null;
}
function Blur(obj){
obj.value==''?obj.value=obj.defaultValue:null;
}
</script>
</head>
<body>
<form action="">
<input type="text" value="Name" onfocus="Focus(this)" onblur="Blur(this)">
<input type="text" value="E-mail" onfocus="Focus(this)" onblur="Blur(this)">
</form>
</body>
</html>

I guess you didn't know about the defaultValue property.

perfectheat
Apr 13th, 2010, 04:37 PM
Thank you guys! You have been very helpful.