In my jsp page i am having two submit buttons. Code snippet is:
<input type="submit" name="btnSubmit" id="btnSubmit" value="abc" onclick="return formCheck3(this)"/>
<input type="submit" name="btnSubmit" id="btnSubmit" value="xyz" onclick="return formCheck3(this)"/>
In formCheck3, in javascript, i am validating whether dropdown is selected and then submitting the form.In my method in action class i am having:
String button=request.getParameter("btnSubmit");
if(button.equals("abc")){
//certain code here
}else if(button.equals("xyz")){
//certain code here
}
This is working fine in IE and mozilla but in chrome i am getting the button value as null.
Can anyone suggest me a way around?
This is not right. Returning
truewould continue the invoking element’s default action, which is in case of<input type="submit">submitting the parent<form>element, which is right, but if you already submit the form beforehand, you’re in essence completely overriding the element’s default action.Remove the
form.submit()call in your JS. Let the<input type="submit">do its default job. This way its parameter name/value will also appear in the request parameter map. In your JS, you should control the submission by only returning eithertrueorfalse.