)",still,submit,despite,failing,validation?" /> Why does my onsubmit="Validate_Submit()" still submit despite failing validation? - Problems and solutions to issues related to Hardware - Programing4Us

Question : Why does my onsubmit="Validate_Submit()" still submit despite failing validation?

Hi experts,

Much as the title says really.  I have attached the relevant code (and yes, it is old!).

What happens is that I get an alert about invalid birth date, click on OK, and the form submits immediately.

Incidentally, the button mouseovers do not work either.

I am using IE8 (compatibility mode).

Could someone help here please?

Ta,  Colin
1:
2:
3:
4:
5:
6:
7:
8:
9:
<form method="post" action="SaveNew.asp" name="FRMNewRec" id="FRMNewRec" onsubmit="Validate_Submit()">
<input type="hidden" name="Dupe">
<input type="hidden" name="CancelForm" value="0">
<table border=1 height=40 rules=none bordercolor="#9A2E00" cellpadding=0 cellspacing=0 align="center" width=100% background="Background.jpg">
       <tr>
          <td align="left"><font face="Arial, Helvetica, Sans Serif" color="#000000"><B>&nbsp&nbspADD RECORD</B></font></td>
          <td align="right">&nbsp&nbsp<button type="submit" NAME="BTNSave" onmouseover="SetStatus('Click here to save this record')" onmouseout="SetStatus('')"><u>S</u>ave Record</button><button name="BtnGetBox" onmouseover="SetStatus('Click here to get the next box number')" onmouseout="SetStatus('')"><u>G</u>et Next Box Number</button><button NAME="BTNMain" onmouseover="SetStatus('Click here to return to the menu')" onmouseout="SetStatus('')"><u>M</u>ain Menu</button>&nbsp&nbsp</td>
       </tr>
</table>
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
function Validate_Submit()
	if frmNewRec.BirthDate.value="" or not isdate(frmNewRec.BirthDate.value) then
		msgbox "Please enter a valid Birth date in the format dd mm yyyy",vbexclamation,"Birthdate"
		frmNewRec.BirthDate.value=""
		frmNewRec.BirthDate.focus
		'frmNewRec.CancelForm.value="1"
		Validate_Submit = false
	else
		'frmNewRec.action="SaveNew.asp" 
		'frmNewRec.CancelForm.value="0"
		Validate_Submit=true 
'		frmNewRec.submit
	end if
end function

Answer : Why does my onsubmit="Validate_Submit()" still submit despite failing validation?

It's because you need to use the return value of the function to prevent the submit, otherwise it will submit the form regardless of te outcome of the function call:

    <form method="post" action="SaveNew.asp" name="FRMNewRec" id="FRMNewRec" onsubmit="return Validate_Submit()">


Random Solutions  
 
programming4us programming4us