Click to See Complete Forum and Search --> : Coding a form to lose a field's value and have it come back


tsteuwer
03-19-2008, 02:29 PM
Hey guys, I was reading over the tutorial on making a text field lose its initial value (http://www.htmlgoodies.com/tutorials/forms/article.php/11895_3479201_2). After reading this, I would like to add extra code to have the initial value come back if the user clicks somewhere else on the page. How do I add this? Someone told me "onblur" but I can't seem to figure it out. Thanks!

ryanbutler
03-19-2008, 03:35 PM
Hmm..where exactly is the click event going to happen to re-initiate the value from the text box? You could grab the value from the text box using a unique ID via JavaScript and then store this in a global variable. Then on a click of a button, alert the value. Something like w/out knowing the specifics:


<html>
<head>
<script type="text/javascript">
var nameInput=document.myForm.getElementById("name");

function MyValue(){
alert("The value of the input box is: " + nameInput);
return false;
}

</script>
</head>

<body>
<form id="myForm" onSubmit="return false;">
Name: <input type="text" id="name">
<input type="submit" value="submit" onClick="MyValue();">
<input type="reset" value="reset">
</form>
</body>
</html>