IE not triggering keyboard event on a form with ONE FIELD

Posted by raj on Stack Overflow See other posts from Stack Overflow or by raj
Published on 2010-03-24T12:11:32Z Indexed on 2010/03/24 12:13 UTC
Read the original article Hit count: 277

Filed under:
|
|

I'm seeing my Friend's code here...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Check action </TITLE>

<script>

    function detectEvent(){
    if(window.event.keyCode==13)
        {
            alert("you hit return!");
        }

    }
</script>


</HEAD>

<BODY>
    <form name="name1" onkeyup="detectEvent()" action="page2.html">
        <p> Field1
            <input type="text" id="text1"/>
        </p>
    </form>
</BODY>
</HTML>

and when he tried entering a value in the textbox and pressed enter, it did not call the detectEvent(). I said, it'll always call onSubmit on enter button..... and he surprised me,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Check action </TITLE>

<script>

    function detectEvent(){
    if(window.event.keyCode==13)
        {
            alert("you hit return!");
        }

    }
</script>


</HEAD>

<BODY>
    <form name="name1" onkeyup="detectEvent()" action="page2.html">
        <p> Field1
            <input type="text" id="text1"/>
        </p>
        <p> Field1
            <input type="text" id="text2"/>
        </p>
    </form>
</BODY>
</HTML>

Now press enter, The function gets called..... Why so!?

Why onKeyUp not called on forms with just one field.!!! am i missing something?

© Stack Overflow or respective owner

Related posts about html

Related posts about events