...

View Full Version : Page reloads when I hit Enter in this textbox



Classic_Cool
07-05-2011, 03:38 AM
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 :confused:

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>

Classic_Cool
07-05-2011, 03:55 AM
:P Never mind, I got it. I had to add onsubmit="return false;" to the form tag. Thanks for looking lol.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum