Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript Client side - Stop form submission 1

Status
Not open for further replies.

cruford

Programmer
Dec 6, 2002
138
US
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:&nbsp;<%=Request.Cookies("FullName")%></td>
<td align="center"><%=Now()%></td>
</tr>
<tr>
<td>Title:&nbsp;</td>
<td><input type="text" name="txtTitle" size="75" maxlength="75"></td>
</tr>
<tr>
<td valign="top">Body:&nbsp;</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?

 
Code:
[red]window.event.returnvalue=false[/red]
will stop it dead in it's tracks.
 
Figured it was something simple, works great now, here's a star for it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top