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

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

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

Post 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?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

chatted with Feyd I did. Resolved the issue he did.

needed "return checkEnt(event)" I did.

happy I am. :D
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

they both have keyCode as evidenced by this: viewtopic.php?t=37059
Post Reply