/    Sign up×
Community /Pin to ProfileBookmark

reset button doesn’t work after textbox onblur event??

Hello!

I haven’t been able to find any answer using the search tool, so here’s my situation/question:

I have a text box with some calculations attached to its onBlur event.
I also have a simple reset button on the form.

[code=html]<form>
<input type=text onBlur=”doThis()”>
<input type=submit><input type=reset>
</form>[/code]

If I type into the textbox, and then click the reset button, the onBlur event code executes (doThis), but the form doesn’t reset.

I know that I can manually write code and attach to a <button> that will clear the form, but I’d much rather just use the reset button.

Why does this happen and how can I get the reset button to work after the onBlur code execution?

Thanks for any help! 😮

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 14.2006 — Have you considered using [B]onkeyup[/B] event instead of [B]onblur[/B] event to do your calculations?
Copy linkTweet thisAlerts:
@sjenkinsdcauthorApr 14.2006 — wouldn't onkeyup method execute after every keypress?

In this case, a number is being entered, and I only want the calculation to happen after the user leaves the textbox. A calculation after every kepress wouldn't be good.

It seems logical that the onBlur event should happen, and then the reset button should go on to do its stuff, but I have to hit reset twice to make it actually clear the form.
Copy linkTweet thisAlerts:
@KorApr 14.2006 — wouldn't onkeyup method execute after every keypress?

In this case, a number is being entered, and I only want the calculation to happen after the user leaves the textbox. A calculation after every kepress wouldn't be good.

It seems logical that the onBlur event should happen, and then the reset button should go on to do its stuff, but I have to hit reset twice to make it actually clear the form.[/QUOTE]


It seems logical to me to show you a very basic exaple of using onkeyup:
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
var names=['a','b']
function addV(f){
var total=0;
for (var i=0;i<names.length;i++){
total+=Number(f[names[i]].value);
}
f['c'].value=total
}
</script>
</head>
<body>
<form>
<input name="a" type="text" size="3" maxlength="3" onkeyup="addV(this.form)">+
<input name="b" type="text" size="3" maxlength="3" onkeyup="addV(this.form)">=
<input name="c" type="text" size="3" maxlength="3">
</form>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@sjenkinsdcauthorApr 14.2006 — Thanks for the post, and the snide 'logical' remark.

There are numerous, numerous ways I could acheive my goal. (why programming is so great!) I do not wish to perform a calculation after every key press. This is a complex tax calculation and it would confuse the user to see a different result after every key press.

My original question still stands:

Why doesn't the standard html reset button work, when it is clicked after an onBlur() event? Does anyone know?
Copy linkTweet thisAlerts:
@KorApr 14.2006 — Thanks for the post, and the snide 'logical' remark.

There are numerous, numerous ways I could acheive my goal. (why programming is so great!) I do not wish to perform a calculation after every key press. This is a complex tax calculation and it would confuse the user to see a different result after every key press.

My original question still stands:

Why doesn't the standard html reset button work, when it is clicked after an onBlur() event? Does anyone know?[/QUOTE]

Then use a button to calculate, if you don't want to confuse your user. The blur event is a weird one, don't count on it.
×

Success!

Help @sjenkinsdc 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.20,
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,
)...