I have a Search TextBox on Master Page,and i want that user write its word and on pressing enter key it should start searching. So onkeypress event i call a function which takes a searching word and pass it to search page.here is my textbox.
<asp:TextBox runat="server" ID="searcht" onkeypress='validateSId($(this),(event))'></asp:TextBox>
This is my function.
function validateSId(txt, e) {
if (e.keyCode == 13) {
var str = txt.val();
window.location = "search.aspx?data=" + str;
}
}
I have another page demo.aspx which inherits master page and it contain one submit button and java script validation function for text boxes which gets fire on On client Click event.here is button.
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
OnClientClick="return DemoCheckFields()"OnClick="btnSubmit_Click" CssClass="btn-red-big btn-big" TabIndex="22"
Now the Problem is when ever i press enter on search textbox,it first execute the DemoCheckFields function and then validateSId(). I want that on pressing enter key from search textbox it should execute only validateSId().
I have Finally solve this issue by using event.preventDefault(); Modified Function is
function validateSId(txt, e) {
if (e.keyCode == 13) {
var str = txt.val();
e.preventDefault();
window.location = "search.aspx?data=" + str;
}
}