Controlling behavior of the Enter key in the form.

Discussion in 'Javascript' started by Amir Hardon, Feb 28, 2004.

  1. Amir Hardon

    Amir Hardon Guest

    I want to call a JS function when Enter is pressed inside the form,
    and when the submit button is clicked I want to submit the form.

    Any simple way for doing this?

    Thanks,
    -Amir.
     
    Amir Hardon, Feb 28, 2004
    #1
    1. Advertisements

  2. Amir Hardon

    Amir Hardon Guest

    Ok, I found a solution:

    function chkent(field, event) {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which :
    event.charCode;
    if (keyCode == 13) {
    jsfunction();
    return false;
    }
    else
    return true;
    }

    <input type="text" onkeypress="return chkent(this, event);">
     
    Amir Hardon, Feb 28, 2004
    #2
    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.