Reputation: 9585
I am facing one problem in the following code , Form is going to submit when i press enter in Keyword text field. there no such enter event bind in java script. Still this problem is happing
But when I remove the <form>
tag it works fine ,
Please help .. if there is any mistake
<form action="" method="post" id="businessSearchForm" name="businessSearchForm">
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" HEIGHT="100%" WIDTH="100%" CLASS="searchproperty">
<TR>
<TD ALIGN="left" COLSPAN="4" class="boldText"> Business Search</TD>
</TR>
<TR>
<TD ALIGN="left" WIDTH="20%" class="boldText"> Search For</TD>
<TD WIDTH="25%"><INPUT TYPE="radio" NAME="searchfor" VALUE="1" checked="checked">Product <INPUT TYPE="radio" NAME="searchfor" VALUE="2">Company</TD>
<TD ALIGN="left" WIDTH="20%" class="boldText"> Business Type</TD>
<TD WIDTH="30%"> <SELECT NAME="businessType" ID="businessType" CLASS="dropDown"></SELECT></TD>
</TR>
<TR>
<TD ALIGN="left" class="boldText"> Country</TD>
<TD> <SELECT ID="country" NAME="country" CLASS="dropDown"></SELECT></TD>
<TD ALIGN="left" class="boldText"> State</TD>
<TD> <SELECT ID="state" NAME="state" CLASS="dropDown"></SELECT></TD>
</TR>
<TR>
<TD ALIGN="left" class="boldText"> Keywords <span class="mendotory">*</span></TD>
<TD COLSPAN="3"> <INPUT TYPE="text" maxlength="40" SIZE="40" tabindex="1" name="keywords" id="keywords" value=""> <INPUT TYPE="button" CLASS="btn" VALUE="Search" ONCLICK="javascript:processBusinessSearch();"/> <a href='#' onclick='javascript:clearBusinessSearch();' ><img src="images/clear.gif" border="0"></a> </TD>
</TR>
</TABLE>
</form>
Upvotes: 1
Views: 302
Reputation: 342635
Something like this should do it:
$("#keywords").keypress(function(e) {
// if 'enter' is pressed
if(e.which == 13) {
return false;
}
});
Upvotes: 1
Reputation: 300845
I'm not sure I've interpreted your question, but I believe what you're wanting is for your processBusinessSearch() function to be called when the form is submitted, regardless of whether the user pressed the submit button or pressed enter.
For this, take a look at the submit event - add a handler for this event which calls your function.
Upvotes: 1
Reputation: 2005
$("#keywords").keypress(function(e){
if (e.which == 13)
$("#businessSearchForm").submit();
});
Upvotes: 0
Reputation: 86729
Try using the onsubmit event on the form instead:
<form onSubmit="return processBusinessSearch()" ...
Upvotes: 0
Reputation: 1758
Another case of the "single textbox submit" problem in IE, see this SO question: "IE needs 2 textboxes to submit a button?".
One workaround is to place another textbox in the form with a style of "display: none"; that way, the enter button won't trigger the submit event. Or, you can use some Javascript to trigger the submit event... it all depends on what you want to achieve.
Upvotes: 1