I have some vbscript validating a form when submitted. I am getting my error messages back properly, but when I click on OK on the popup error the form is submitted anyway. How do I stop the form from being submitted if there is an error? Here is my code below:
<Script Language = "VBScript">
Function frm_onSubmit()
Dim nErr
If document.frmAnnouncement.txtTitle.Value = "" Then
sMsg = sMsg & "Missing title of announcement" & VbCrLf
nErr = 1
End If
If document.frmAnnouncement.txtBody.Value = "" Then
sMsg = sMsg & "Missing body of announcement" & VbCrLf
nErr = 1
End If
Select Case nErr
Case 1
MsgBox sMsg,vbOKOnly,"Missing Information"
frm_onSubmit = False
Case Else
frm_onSubmit = True
End Select
End Function
</Script>
<%Select Case Request.QueryString("CMD")
Case "Add"%>
<form name="frmAnnouncement" method="get" action="Announcements.asp" onsubmit="frm_onSubmit();">
<table align=center width="100%" style="background: navy; color: white; font-size: 10pt; font-weight: bold">
<tr><td align=center><font color="white">Add Announcement</font></td></tr>
</table>
<table class="TDBody" align="left" border="1" cellpadding="1" cellspacing="1">
<tr>
<td>Name: <%=Request.Cookies("FullName")%></td>
<td align="center"><%=Now()%></td>
</tr>
<tr>
<td>Title: </td>
<td><input type="text" name="txtTitle" size="75" maxlength="75"></td>
</tr>
<tr>
<td valign="top">Body: </td>
<td><textarea name="txtBody" rows="10" cols="75"></textarea></td>
</tr>
<tr><td colspan="2" align="right"><input type="submit" name="CMD" value="Submit"></td></tr>
</table>
</form>
There is other cases to my selected statement but I wanted to spare you the long post. Like I said my error messagebox comes up fine, but when I click ok to the error the form gets submitted regardless. How do I stop that?
<Script Language = "VBScript">
Function frm_onSubmit()
Dim nErr
If document.frmAnnouncement.txtTitle.Value = "" Then
sMsg = sMsg & "Missing title of announcement" & VbCrLf
nErr = 1
End If
If document.frmAnnouncement.txtBody.Value = "" Then
sMsg = sMsg & "Missing body of announcement" & VbCrLf
nErr = 1
End If
Select Case nErr
Case 1
MsgBox sMsg,vbOKOnly,"Missing Information"
frm_onSubmit = False
Case Else
frm_onSubmit = True
End Select
End Function
</Script>
<%Select Case Request.QueryString("CMD")
Case "Add"%>
<form name="frmAnnouncement" method="get" action="Announcements.asp" onsubmit="frm_onSubmit();">
<table align=center width="100%" style="background: navy; color: white; font-size: 10pt; font-weight: bold">
<tr><td align=center><font color="white">Add Announcement</font></td></tr>
</table>
<table class="TDBody" align="left" border="1" cellpadding="1" cellspacing="1">
<tr>
<td>Name: <%=Request.Cookies("FullName")%></td>
<td align="center"><%=Now()%></td>
</tr>
<tr>
<td>Title: </td>
<td><input type="text" name="txtTitle" size="75" maxlength="75"></td>
</tr>
<tr>
<td valign="top">Body: </td>
<td><textarea name="txtBody" rows="10" cols="75"></textarea></td>
</tr>
<tr><td colspan="2" align="right"><input type="submit" name="CMD" value="Submit"></td></tr>
</table>
</form>
There is other cases to my selected statement but I wanted to spare you the long post. Like I said my error messagebox comes up fine, but when I click ok to the error the form gets submitted regardless. How do I stop that?