SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Location
    Atlantis
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Enter key - don't submit but trigger action

    Hello

    I need to trigger a function but do not submit form on enter key within my form. I use the following for calling the function, but it submits and calls the function at the same time.


    <input type="text" name="xxx" onkeypress="entercheck('122');">

    function entercheck(id) {

    if (window.event && window.event.keyCode == 13) {
    sendquery(id);
    }

    }

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    catch the event on keydown instead of keypress,
    and return false from the handler to stop it reaching submit

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Location
    Atlantis
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Changed to

    <input type="text" name="xxx" onkeydown="entercheck('122');">

    function entercheck(id) {

    if (window.event && window.event.keyCode == 13) {
    sendquery(id);
    }
    return false;
    }

    No change


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •