I have JSP page which has a form with text fields and checkboxes. These fields are displayed by applying XSL on an XML.
There is also is submit button in the form. This button is coded for in the JSP page.
<input type="button" name="btnSubmit" value="Search" onClick="javascript:submit
Srch('chan
ge');" />
So that the form is submitted when the user presses ENTER key, following code has been written in this page
/* This will submit the form upon pressing enter key */
document.onkeydown = function() {
return alertkey(event)
};
function alertkey(e) {
if( !e ) {
if( window.event ) {
//Internet Explorer
e = window.event;
} else {
return;
}
}
if( typeof( e.keyCode ) == 'number' ) {
//DOM
e = e.keyCode;
} else if( typeof( e.which ) == 'number' ) {
//NS 4 compatible
e = e.which;
} else if( typeof( e.charCode ) == 'number' ) {
//also NS 6+, Mozilla 0.9+
e = e.charCode;
} else {
//total failure, we have no way of obtaining the key code
return;
}
if(e==13) {
submitadvancedSearch('chan
ge');
return false;
}
}
</script>
This JSP page includes another JSP page which displays a left navigation in the page specified above. This left navigation has a form with only one text field.
<input type="text" name="word" onkeypress="javascript:sub
mitEnterKe
y();"/>
This used to work fine befroe the above specified Javascript was added in the main page. But now when the user is in this text field and presses ENTER then the form specified above (in the main page) gets submitted.
Please tell me how to resolve this issue.
Start Free Trial