Scorez2000
Programmer
I'm tring to write some validation for a form, but even when I get a pop up saying that the data input is not as required, the form still tries to submit.
How do I stop this form submitting?
Here is the code:
-----------------------------------------------------
<html>
<head>
<title></title>
<style type="text/css">
body{font-family:verdana}
table{font-family:verdana;font-size:xx-small}
th{background-color:#999999}
</style>
<script language="vbscript">
'This script runs client-side (WD)
'This validates the info that the user inputs into the form, making sure that the info makes sense and the whole form is filled in (WD)
Sub Wibble()
if tstFrm.tstNam.value = "" then
Alert "Please insert your name."
tstFrm.tstNam.focus
Exit Sub
elseif isdate(tstFrm.tstDob.value) = false then
Alert "Please enter a valid date for your date of birth."
tstFrm.tstDob.focus
Exit Sub
elseif tstFrm.tstNat.value = "0" then
Alert "Please select a nationality."
requestleave.rlLast.focus
Exit Sub
End If
btnSubmitClicked = MsgBox ("Are you sure you want to continue?", VBYesNo, "Please Confirm")
If btnSubmitClicked = 6 then
Call tstFrm.Submit()
end if
End Sub
</script>
</head>
<body>
<p>This Is My Test Form.</p>
<table>
<form name="tstFrm" id="tstFrm" method="post" action="testpost.asp" onSubmit="Wibble">
<tr>
<th>Name</th>
<th>D.O.B.</th>
<th>Nationality</th>
</tr>
<tr>
<td><input name="tstNam" id="tstNam"></td>
<td><input name="tstDob" id="tstDob"></td>
<td><select name="tstNat" id="tstNat"><option value="0"></option><option value="1">British</option><option value="2">Irish</option></select></td>
</tr>
<tr>
<td colspan="3" align="right"><input type="submit" Value="Submit" name="tstSubmit" id="tstSubmit"></td>
</tr>
</form>
</table>
</body>
</html>
How do I stop this form submitting?
Here is the code:
-----------------------------------------------------
<html>
<head>
<title></title>
<style type="text/css">
body{font-family:verdana}
table{font-family:verdana;font-size:xx-small}
th{background-color:#999999}
</style>
<script language="vbscript">
'This script runs client-side (WD)
'This validates the info that the user inputs into the form, making sure that the info makes sense and the whole form is filled in (WD)
Sub Wibble()
if tstFrm.tstNam.value = "" then
Alert "Please insert your name."
tstFrm.tstNam.focus
Exit Sub
elseif isdate(tstFrm.tstDob.value) = false then
Alert "Please enter a valid date for your date of birth."
tstFrm.tstDob.focus
Exit Sub
elseif tstFrm.tstNat.value = "0" then
Alert "Please select a nationality."
requestleave.rlLast.focus
Exit Sub
End If
btnSubmitClicked = MsgBox ("Are you sure you want to continue?", VBYesNo, "Please Confirm")
If btnSubmitClicked = 6 then
Call tstFrm.Submit()
end if
End Sub
</script>
</head>
<body>
<p>This Is My Test Form.</p>
<table>
<form name="tstFrm" id="tstFrm" method="post" action="testpost.asp" onSubmit="Wibble">
<tr>
<th>Name</th>
<th>D.O.B.</th>
<th>Nationality</th>
</tr>
<tr>
<td><input name="tstNam" id="tstNam"></td>
<td><input name="tstDob" id="tstDob"></td>
<td><select name="tstNat" id="tstNat"><option value="0"></option><option value="1">British</option><option value="2">Irish</option></select></td>
</tr>
<tr>
<td colspan="3" align="right"><input type="submit" Value="Submit" name="tstSubmit" id="tstSubmit"></td>
</tr>
</form>
</table>
</body>
</html>