Page 1 of 1

enter submits a form...don't want it to

Posted: Wed Aug 24, 2005 10:35 am
by Burrito
A hidden div element I have. Use this element to show a search function I do. Two fields it contains.

Code: Select all

<div id="searchdiv" class="slide">
<table class="tablez">
<tr>
<td>
<input type="radio" name="searchcri" value="school" checked="checked"> School Name<br>
<input type="radio" name="searchcri" value="district"> District<br>
<input type="radio" name="searchcri" value="state"> State<br>
<input type="radio" name="searchcri" value="firstname"> First Name<br>
<input type="radio" name="searchcri" value="lastname"> Last Name<br>
<input type="radio" name="searchcri" value="homephone"> Home Phone<br>
<input type="radio" name="searchcri" value="email"> Email Address<br>
<input type="text" name="searchstr" onKeyPress="checkEnt(event)">
<input type="button" value="go" onClick="searchIt(),slideEr('searchdiv',true);" class="butt">
</td>
</tr>
</table>
</div>
when hitting enter on the text field, the "parent" form is submitted the problem is.

tried creating a function to check for the enter key I have

Code: Select all

<script>
function checkEnt(evt)
{
	if(evt.keyCode == 13)
	{
		searchIt();
		slideEr('searchdiv',true);
		return;
	}
}
</script>
aware I am that works only in IE this does...the issue this is not.

prevent the form from submitting I need. Possible this is?

Posted: Wed Aug 24, 2005 10:49 am
by Burrito
chatted with Feyd I did. Resolved the issue he did.

needed "return checkEnt(event)" I did.

happy I am. :D

Posted: Wed Aug 24, 2005 10:51 am
by anjanesh
You may want to check for both keyCode and which - I dont remember which browser uses what - but IE uses one and Netscape, Mozilla uses the other.

Code: Select all

if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;

Posted: Wed Aug 24, 2005 12:09 pm
by feyd
they both have keyCode as evidenced by this: viewtopic.php?t=37059