/    Sign up×
Community /Pin to ProfileBookmark

Coding a form to lose a field’s value and have it come back

Hey guys, I was reading over the tutorial on making a text field lose its initial value ([URL=”http://www.htmlgoodies.com/tutorials/forms/article.php/11895_3479201_2″]http://www.htmlgoodies.com/tutorials/forms/article.php/11895_3479201_2[/URL]). 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!

to post a comment
HTML

1 Comments(s)

Copy linkTweet thisAlerts:
@ryanbutlerMar 19.2008 — 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:

[CODE]
<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>[/CODE]
×

Success!

Help @tsteuwer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...