B
Brian
Hi all... This question is more for the GURUs out there. It is not a
question on how to do something, but why it happens, and I am trying to
figure out if there is a pattern. I am using IE, but this pattern also
happens in Mozilla, but not always the same way... I am not as interested in
how the browsers are different, but the big question is: Is there a pattern
to what type of actions are delayed for after the scripts have finished, and
what type of actions happen instantly?
Here is a snippit, to start out the discussion:
alert(location.href)
location.href = "SOMEPLACE_NOT_HERE"
alert(location.href)
If you run this code, the alert message will respond with the same
answer...the current page. Even though the href string is set, the value is
delayed. It is not until the script block has finished that the location
changes, and the string value has changed.
Now, under the hood, I understand what is going on... The JavaScript engine
executes code on a DOM model, maintained by the browser. The JS engine
needs to finish before control is given back to the browser, to act on the
change. In the mean time, since the actual location has not changed,
reading the location.href stays the same.
Ok, moving on... Look at the following code:
function ButtonWasClicked ()
{
document.forms['form_id'].elements['text_id'].value = "WOOHOO";
document.forms['form_id'].submit();
document.forms['form_id'].elements['text_id'].value = "BLUBBER";
alert(document.forms['form_id'].elements['text_id'].value
}
This code will also wait until the script has ended to run submit, so the
alert will show "BLUBBER"... BUT, the actual submission will be of "WOOHOO".
Lets replace the alert with another submit:
function ButtonWasClicked ()
{
document.forms['form_id'].elements['text_id'].value = "WOOHOO";
document.forms['form_id'].submit();
document.forms['form_id'].elements['text_id'].value = "BLUBBER";
document.forms['form_id'].submit();
}
In this case, only ONE of the submits had occurred... I did a scan of the
HTTP traffic to verify that this was the case. In IE, BLUBBER is sent, and
in Mozilla, WOOHOO is sent to the form handler.
I hope this makes sense... I can elaborate more if necessary.
Thanks,
Brian
question on how to do something, but why it happens, and I am trying to
figure out if there is a pattern. I am using IE, but this pattern also
happens in Mozilla, but not always the same way... I am not as interested in
how the browsers are different, but the big question is: Is there a pattern
to what type of actions are delayed for after the scripts have finished, and
what type of actions happen instantly?
Here is a snippit, to start out the discussion:
alert(location.href)
location.href = "SOMEPLACE_NOT_HERE"
alert(location.href)
If you run this code, the alert message will respond with the same
answer...the current page. Even though the href string is set, the value is
delayed. It is not until the script block has finished that the location
changes, and the string value has changed.
Now, under the hood, I understand what is going on... The JavaScript engine
executes code on a DOM model, maintained by the browser. The JS engine
needs to finish before control is given back to the browser, to act on the
change. In the mean time, since the actual location has not changed,
reading the location.href stays the same.
Ok, moving on... Look at the following code:
function ButtonWasClicked ()
{
document.forms['form_id'].elements['text_id'].value = "WOOHOO";
document.forms['form_id'].submit();
document.forms['form_id'].elements['text_id'].value = "BLUBBER";
alert(document.forms['form_id'].elements['text_id'].value
}
This code will also wait until the script has ended to run submit, so the
alert will show "BLUBBER"... BUT, the actual submission will be of "WOOHOO".
Lets replace the alert with another submit:
function ButtonWasClicked ()
{
document.forms['form_id'].elements['text_id'].value = "WOOHOO";
document.forms['form_id'].submit();
document.forms['form_id'].elements['text_id'].value = "BLUBBER";
document.forms['form_id'].submit();
}
In this case, only ONE of the submits had occurred... I did a scan of the
HTTP traffic to verify that this was the case. In IE, BLUBBER is sent, and
in Mozilla, WOOHOO is sent to the form handler.
I hope this makes sense... I can elaborate more if necessary.
Thanks,
Brian