Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2011
    Posts
    30
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Page reloads when I hit Enter in this textbox

    I've got this form on my page that contains a search box and a select box full of employee names. When you type a few letters in the search box it scrolls through the listbox to the first match and then if you click on that name it executes a function.

    Today though one of my coworkers pointed out that some people would just hit enter inside the search box and he's right about that. So I looked around and found the solution for it, it's the onkeydown event I added to the search box.

    Weird thing is though when you type a name in the box and hit enter it executes properly and then the page immediately reloads

    Without the onkeybown event, hitting Enter still makes the page reload so it's gotta be something about the form. Can anyone pick out the bug? Thanks.

    <form name="people_form" style="margin: 0px">

    <input type="text" id="peoplesearch" name="peoplesearch" onkeydown="if (event.keyCode == 13) search_onblur()" onblur="search_onblur()" onkeyup="suggestName();" onfocus="this.value=''" style="margin: 0px 0px 5px 0px; padding: 0px; width: 215px"></input>

    <select onchange="display.apply(this, this.value.split(','))" size="15" id="People" name="People" style="border-style: none; height:244px; width:220px; margin-bottom: 15px;">
    <option>Loading</option>
    </select>

    </form>

  • #2
    New Coder
    Join Date
    Jun 2011
    Posts
    30
    Thanks
    4
    Thanked 0 Times in 0 Posts
    :P Never mind, I got it. I had to add onsubmit="return false;" to the form tag. Thanks for looking lol.


  •  

    Posting Permissions

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