Please see the code snippet below:
<!DOCTYPE html>
<html>
<body>
<form name="editProfileForm" method="post" action="profileDataCollection.do">
<input type="text" id="credit-card" name="credit-card" onfocus="unmaskCC(this);" onblur="maskCC(this);" />
<input type="hidden" name="ccValue" value=""/>
<button type="submit">Continue</button>
</form>
<script type="text/javascript">
function unmaskCC(field){
/*code for unmasking credit card field*/
alert("unmask called"); /*For demo purpose introduced an alert*/
}
function maskCC(field){
/*code for masking the credit card field*/
alert("mask called"); /*For demo purpose introduced an alert*/
}
</script>
</body>
</html>
Problem Description: I have the above code in one of my JSP pages. When this page is rendered in Internet Explorer 10, I see a strange problem. When I hit the continue button (i.e. form's submit button), the onfocus of the credit-card field is automatically triggered and the function "unmaskCC" is called. The form does not submit. This problem occurs only in IE10.
I have tested the same page with Google Chrome, Firefox, Safari (Desktop, Tablet, Mobile) and everywhere it seems to be working fine.
I initially thought that clicking submit is causing "event bubbling", but that cannot happen, since continue button is a sibling of credit-card field.
Also Note: I have the workaround for this issue i.e. changing the button type="button"
and then submitting the form via onclick javascript i.e.
document.getElementById("editProfileForm").submit();
which works fine as expected.
But I am unable to understand what is causing the <button type="submit">
to not work as expected.
I am going crazy with this IE10 specific issue. Any help here would be highly appreciated.
Thanks in advance.