Please find the pasted html,
<html>
<script language="JavaS cript" src="cal.js"></script><!-- Date only with
year scrolling -->
</head>
<BODY onLoad="showDet ails()">
<script language="javas cript">
function validatePage(){
return true;
}
function updateDetails() {
var basicStaffNoChe ck=false;
basicStaffNoChe ck=basicStaffVa lidation();
if(basicStaffNo Check)
{
var canSub = false;
if(validatePage ()){
with(document.f orms[0]){
if(hidDataChnge d.value!='1')
alert("No records updated. Please update atleast one record and
click OK");
else{
document.forms[0].btnSubmit.disa bled=true;
hidActionId.val ue="OK";
submit();
}
}
}
}
}
function showDetails(){
document.getEle mentById("Staff Number").focus( );
}
function displayError()
{
alert("displayE rror");
if(document.get ElementById('St affNumber').val ue == "")
{
alert("Please enter Staff Number");
document.getEle mentById('Staff Number').focus( );
}
if(document.get ElementById('St affNumber').val ue != "")
{
flag=validateSt affNo();
alert("returnin g from validateStaffNo "+flag);
if(flag)
{
document.forms[0].submit();
}
else
{
alert("Ïnside else");
return;
}
}
}
function validateStaffNo (){
var val = document.getEle mentById('Staff Number').value;
var patternBasic = new RegExp("^[0-9]{6}"); //matches alphanumeric
atleast 6 characters
var result = patternBasic.te st(val);
if(!result)
{
alert("Alert 1 Please Enter a valid Staff Number.Please enter leading
zeroes if applicable.");
document.getEle mentById('Staff Number').focus( );
return false;
}
else
return true;
}
function KeyDownHandler( Btn)
{
if (event.keyCode == 13)
{
Btn.click();
}
}
</script>
<FORM name="frmInvoic e" method="post" onsubmit="alert ('Why does it
submit');">
<input type="hidden" name="hidAction Id">
<!-- input type="hidden" name="hidPassId " -->
<input type="hidden" name="hidPassId Val">
<br>
<TABLE width="80%" summary="" border="0" cellspacing="0"
cellpadding="0" >
<TR>
<TD align="right" nowrap>
</TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD width="30%" height="3"></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD align="right" nowrap><span class="OraPromp tText"><LABEL>S taff
Number </LABEL></SPAN>
</TD>
<TD ><input id="StaffNumber " class="OraField Text" onchange=""
name="StaffNumb er" size="10" type="text" maxlength="6"
onKeyDown="KeyD ownHandler(Disp layDetails);">
</TD>
<TD width="15%"><in put type="button" id="DisplayDeta ils"
name="DisplayDe tails" value="Display Personal Details"
onClick="displa yError();">
</TD>
</TR>
</TABLE>
</form>
</body>
</html>
Staff No is validated to be exactly 6 digits numeric.
On click of the "display personal details" button with the mouse,The
page behaves fine.But on hit of ENTER...after entering some three or
four digits in the staff No text box.Its validating and giving the
error message" Alert 1 Please Enter a valid Staff Number.Please enter
leading zeroes if applicable." Then form submits.On submit alert is
fired.
I dont want the submit to happen when the client validation
fails.Strangely the submit does not happen on click of the button using
mouse.Çan anybody help me please.