Vicky
Vicky

Reputation: 9585

Auto Submitting the Form

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">&nbsp;Business Search</TD>
                    </TR>
                    <TR>
                        <TD ALIGN="left" WIDTH="20%" class="boldText">&nbsp;Search For</TD>
                        <TD WIDTH="25%"><INPUT TYPE="radio" NAME="searchfor" VALUE="1" checked="checked">Product&nbsp;<INPUT TYPE="radio" NAME="searchfor" VALUE="2">Company</TD>
                        <TD ALIGN="left" WIDTH="20%" class="boldText">&nbsp;Business Type</TD>
                        <TD WIDTH="30%">&nbsp;<SELECT NAME="businessType" ID="businessType" CLASS="dropDown"></SELECT></TD>
                    </TR>
                <TR>
                    <TD ALIGN="left" class="boldText">&nbsp;Country</TD>
                    <TD>&nbsp;<SELECT ID="country" NAME="country" CLASS="dropDown"></SELECT></TD>
                    <TD ALIGN="left" class="boldText">&nbsp;State</TD>
                    <TD>&nbsp;<SELECT ID="state" NAME="state" CLASS="dropDown"></SELECT></TD>
                </TR>
                <TR> 
                    <TD ALIGN="left" class="boldText">&nbsp;Keywords&nbsp;<span class="mendotory">*</span></TD>
                    <TD COLSPAN="3">&nbsp;<INPUT TYPE="text" maxlength="40" SIZE="40" tabindex="1" name="keywords" id="keywords" value="">&nbsp;&nbsp;<INPUT TYPE="button" CLASS="btn" VALUE="Search" ONCLICK="javascript:processBusinessSearch();"/>&nbsp;<a href='#'  onclick='javascript:clearBusinessSearch();' ><img src="images/clear.gif" border="0"></a>&nbsp;</TD>
                </TR>
            </TABLE>            
        </form>

Upvotes: 1

Views: 302

Answers (5)

karim79
karim79

Reputation: 342635

Something like this should do it:

$("#keywords").keypress(function(e) {
    // if 'enter' is pressed
    if(e.which == 13) {
        return false;
    }
});

Upvotes: 1

Paul Dixon
Paul Dixon

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

kb.
kb.

Reputation: 2005

$("#keywords").keypress(function(e){ 
  if (e.which == 13)
    $("#businessSearchForm").submit(); 
});

Upvotes: 0

Justin
Justin

Reputation: 86729

Try using the onsubmit event on the form instead:

<form onSubmit="return processBusinessSearch()" ...

Upvotes: 0

tijmenvdk
tijmenvdk

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

Related Questions