consequetive events + global variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sandman

    consequetive events + global variables

    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="javas cript">
    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="retur n SubmitFunc();">
    <input type="text" name="test" onBlur="BlurFun c();">
    <input type="submit">
    </form>
    </body>
    </html>
  • Robert

    #2
    Re: consequetive events + global variables

    In article <46adf552.04050 40604.18b52257@ posting.google. com>,
    luyckxsteven@ho tmail.com (Sandman) wrote:
    [color=blue]
    > 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?[/color]


    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

    Comment

    Working...