Event handling in IE?

B

Brian Genisio

Ok, I am confused. The following code works in Mozilla 1.5, but it
doesnt work in IE 6.

The wierd thing about the IE failure, is that the text is changed in the
onBlur event, but when I run alert, it is not changed yet.

Anyone know why this is? I am a bit baffled.

Brian

<HTML>
<HEAD>
<TITLE>Blur Test</TITLE>
</HEAD>


<BODY>
<SPAN id=mySPAN>BeforeCallback</SPAN>

<FORM name=myForm>
<INPUT id=myInput1 name=myInput1 type=text
onBlur="document.getElementById('mySPAN').innerHTML = 'blurred';">
</FORM>

<SCRIPT type="text/javascript">

input1 = document.getElementById("myInput1");
input1.focus();
input1.blur();

alert(document.getElementById('mySPAN').innerHTML);
</SCRIPT>

</BODY>
</HTML>
 
N

Nick Howes

shouldn't

input1 = document.getElementById("myInput1");

be

var input1 = document.getElementById("myInput1");
^^^
 
B

Brian Genisio

Nick said:
shouldn't

input1 = document.getElementById("myInput1");

be

var input1 = document.getElementById("myInput1");
^^^

Sure... I suppose (do not top post on this group please). Using var
doesnt really matter for this example. This is just a paird down
version of what I really have, to show the problem... and your comment
does nothing to make progress towards solving the problem... purely
symantecs... optional symantecs in this case.

Anyways, another curious thing is that if I call the exact same alert
call immediately after the first one, the second one reports correctly,
and the first one is still broken.

Sigh. I really cannot understand what is going on here. I have a
pretty good grasp of the inner-workings of Javascript, butI am not sure
why IE does this.

Brian
 
M

Mike

replace
alert(document.getElementById('mySPAN').innerHTML);

with

setTimeout(test,100)
function test(){
alert(document.getElementById('mySPAN').innerHTML);
}


This worked in IE 6.0. I've experienced weird redering issues with IE
during the initial parsing. In this case IE 6.0 diplayed the "blurred"
mesage correctly but the alert was wrong. Like it executed the script before
it resets the innerHTML value. Perhaps the scripted events are not executed
until after the document status is complete. Dunno.

Sorry no real answer just a work around.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top