Controlling behavior of the Enter key in the form.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Amir Hardon

    Controlling behavior of the Enter key in the form.

    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.
    --
    Remove the 'dont_spam_me' and the dashes before mailing me.
  • Amir Hardon

    #2
    Re: Controlling behavior of the Enter key in the form.

    Amir Hardon wrote:
    [color=blue]
    > 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.[/color]
    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="ret urn chkent(this, event);">

    --
    Remove the 'dont_spam_me' and the dashes before mailing me.

    Comment

    Working...