Monday 15 June 2015

jquery - Preventing form submittion with enter key on all but one submit button -



jquery - Preventing form submittion with enter key on all but one submit button -

i have aspx web form master page contains 2 submit buttons, 1 business relationship login , 1 site search. want come in key submit login not other button on site login more used. every time nail come in after entering login info search button fires , brings me empty results page. next i've tried without success:

1) create login button type=submit , others type=button

2) set usesubmitbehavior="false" buttons except login set true.

3) utilize various jquery code on id of inputs disable keydown event come in key.

the code had effect following, disable come in key every thing. when substituted window selector failed work. since whole page form did not add together additional form tags. there must way allow come in key work on 1 button. thanks

$(function () { $(window).keydown(function (event) { if (event.keycode == 13) { event.preventdefault(); homecoming false; } }); }); search: <div id="searchform"> <fieldset> <asp:textbox id="searchquery" runat="server" size="15" /> </fieldset> <asp:imagebutton id="searchbutton" runat="server" onmouseover="this.src='/resources/buttons/search_hover.png'" onmouseout="this.src='/resources/buttons/search_active.png'" imageurl="/resources/buttons/search_active.png" type="button" style="font-size: 11px;" class="searchbtn" alt="search" onclick="searchbutton_click" usesubmitbehavior="false" causesvalidation="false" /> </div> login: <div id="logonbox"> <asp:label id="label1" class="loginlabel1" runat="server" text="account number"></asp:label> <asp:textbox id="acctnum" class="acctnumtexbox" runat="server"></asp:textbox> <asp:label id="label2" runat="server" class="loginlabel2" text="access code"></asp:label> <asp:textbox id="mtrnum" class="mtrnumtexbox" runat="server"></asp:textbox> <asp:imagebutton id="login1" type="submit" runat="server" class="boxsubmitbtn" src="/resources/buttons/login.gif" onclick="loginbtn_click" usesubmitbehavior="true" causesvalidation="false" /> <p> <a href="/accounts/accounts.aspx">need help logging in?</a> </p> </div>

there many ways accomplish want, easiest find is:

in code behind, in page load method add together line :

protected void page_load(object sender, eventargs e) { this.form.defaultbutton = login1.uniqueid; }

jquery webforms master-pages form-submit enter

No comments:

Post a Comment