onkeypress, enter and iexplorer

Discussion in 'Javascript' started by Juan, Dec 5, 2005.

  1. Juan

    Juan Guest


    I'm having a problem with a simple javascript code that checks if the
    enter key had been pressed or not. The code works propertly in mozilla,
    but in iexplorer it only works one time, the second one the event isn't
    throw any more, and I can't catch it.

    Anyone can help me?

    this is the sample code

    function searchIntro(oEvent)
    if (oEvento.keyCode)
    iAscii = oEvent.keyCode;
    else if (oEvent.which)
    iAscii = oEvent.which;
    return false;
    if (iAscii == 13)


    <input type="text" id ="textBoxName1" name="CCO" size="69"

    Thanks a lot
    Juan, Dec 5, 2005
    1. Advertisements

  2. Juan

    Evertjan. Guest

    Juan wrote on 05 dec 2005 in comp.lang.javascript:
    should be: SearchIntro(oEvent)
    case sensitive!!
    should be: oEvent.keyCode
    a return value is not used by onkeypress
    A shorter version of your function is:

    function SearchIntro(oEvent){
    if ((oEvent.keyCode && oEvent.keyCode==13)
    || (oEvent.which && oEvent.which==13)) {
    Evertjan., Dec 5, 2005
    1. Advertisements

  3. Juan

    Juan Guest

    Thanks evertjan, but the trouble's still here : I made a mistakes
    copying function to this message :), but the case sensitive is
    correctly implemented.

    It only works the first time, the second one, on Internet Explorer,
    fails and doesn't capture any other onkeypress event.Mozilla runs fine
    the code everytime I use it.

    whats happening?


    Evertjan. ha escrito:
    Juan, Dec 7, 2005
  4. Juan

    Evertjan. Guest

    Juan wrote on 07 dec 2005 in comp.lang.javascript:
    [please do not toppost on usenet]

    That depends on your function sendData().
    Always try an adviced code on itself first.
    This works every time in IE:

    <script type='text/javascript'>

    function SearchIntro(oEvent){
    if ((oEvent.keyCode && oEvent.keyCode==13)
    || (oEvent.which && oEvent.which==13)) {
    alert('<return> detected');

    <input onkeypress='SearchIntro(event)'>
    Evertjan., Dec 7, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.