By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,944 Members | 1,656 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,944 IT Pros & Developers. It's quick & easy.

consequetive events + global variables

P: n/a
Below you find a small test page.
I contains an input box, with an onBlur event, and a form, with an
onSubmit event.

When I place the cursor in the text box and push ENTER, first the
onBlur event and then the onSubmit event is raised.
The onBlur event displays the value of the global variable [true], it
changes the value of the global variable to [false] and displays it
again [false].
The onSubmit event simply displays the value of the global variable
[true], which is the original value, not the new. Huh?

Why doesn't the onSubmit event notice that the global variable has
changed?

<html>
<head>
<script language="javascript">
var something = true;
function BlurFunc() {
alert('begin BlurFunc: ' + something);
something = false;
alert('begin BlurFunc: ' + something);
}
function SubmitFunc() {
alert('begin SubmitFunc: ' + something);
return false;
}
</script>
</head>
<body>
<form name="frmTest" method="post" action="steven.asp"
onSubmit="return SubmitFunc();">
<input type="text" name="test" onBlur="BlurFunc();">
<input type="submit">
</form>
</body>
</html>
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <46**************************@posting.google.com >,
lu**********@hotmail.com (Sandman) wrote:
Below you find a small test page.
I contains an input box, with an onBlur event, and a form, with an
onSubmit event.

When I place the cursor in the text box and push ENTER, first the
onBlur event and then the onSubmit event is raised.
The onBlur event displays the value of the global variable [true], it
changes the value of the global variable to [false] and displays it
again [false].
The onSubmit event simply displays the value of the global variable
[true], which is the original value, not the new. Huh?

Why doesn't the onSubmit event notice that the global variable has
changed?

Perhaps the page was being reloaded. When you go to a new page then
press the back arrow, you get up your original page. The page is
reloaded. This sets the variable something to true. Some browsers will
let the form data filled in. You can now press enter to submit the form
and you will see the original value of true in the global variable.

The alert in the onblur event may have had a bit of a side effect or I
have not used enough alerts to know all the features. When I filled in
the data then clicked on the submit button, I got the onBlur alerts, but
the script didn't move directly to the submit form events. In IE on the
mac, the IE window lost focus. I had to click on the window to gain
focus. Once I clicked, the submit event ran. Netscape 7.1, I had to do
a second click in Netscape 7.1 too.

You canceled the submit which made it hard for me to follow what was
going on. When I put in a valid action and changed return to true. I
didn't see any problems with the setting of the variable something.
Robert
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.