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!

Client side validation - function variable problem

Status
Not open for further replies.

cruford

Programmer
Dec 6, 2002
138
US
I can't seem to figure this out. I need to pass the name of my form from my <form> tag to a client side vbscript function.

So far this is what I have:

<Script Language = "VBScript">
Function frm_onSubmit(frmName)
Dim nErr, sMsg
Select Case frmName
Case "frmAddAnnouncement"
If document.frmAddAnnouncement.txtTitle.Value = "" Then
sMsg = sMsg & "You must provide a title for your announcement." & VbCrLf
nErr = 1
End If
If document.frmAddAnnouncement.txtBody.Value = "" Then
sMsg = sMsg & "You must provide a body for your announcement." & VbCrLf
nErr = 1
End If
Select Case nErr
Case 1
MsgBox sMsg,vbOKOnly,"Missing Information"
window.event.returnValue = False
Case Else
window.event.returnValue = True
End Select
Case Else
'Some other form code here
End Select
End Function
</Script>

<%Select Case Request.QueryString("CMD")
Case "Add"%>
<form name="frmAddAnnouncement" method="post" action="Announcements.asp" onsubmit="frm_onSubmit("frmAddAnnouncement");">
<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="cmdAdd" value="Submit"></td></tr>
</table>
</form>
<%Case "Edit"
sSQL = "SELECT * FROM ztblAnnouncements WHERE ID = " & Request.QueryString("ID")
Set RS = Conn.Execute(sSQL,,1)%>
<form name="frmEditAnnouncement" method="get" action="Announcements.asp" onsubmit="frm_onSubmit("frmEditAnnouncement")">
<table align=center width="100%" style="background: navy; color: white; font-size: 10pt; font-weight: bold">
<tr><td align=center><font color="white">Edit Announcement</font></td></tr>
</table>
<table class="TDBody" border="0" cellpadding="1" cellspacing="1">
<tr>
<td>Title:&nbsp;</td><td><input name="txtTitle" type="text" size="75" maxlength="75" value="<%=RS.Fields("Subject")%>"></td>
</tr>
<tr>
<td valign="Top">Body:&nbsp;</td><td><textarea name="txtBody" rows="10" cols="75"><%=RS.Fields("Summary")%></textarea></td>
</tr>
<tr>
<td align="right" colspan="2"><input type="hidden" size="4" name="ID" value="<%=Request.querystring("ID")%>">
<input type="submit" name="CMD" value="Update"</td>
</tr>
</table>
</form>

Am I close or is this even possible?
 
Ok I changed my client side script to pull a cookie I write when the form is written in HTML (<form name="frmAddAnnouncement" method="post" action="Announcements.asp" onsubmit="frm_onSubmit(<%response.cookies("frmName") = "frmAddAnnouncement"%>);">).

<Script Language = "VBScript">
Function frm_onSubmit()
Dim nErr, sMsg
Select Case <%=request.cookies("frmName")%>
Case "frmAddAnnouncement"
If document.frmAddAnnouncement.txtTitle.Value = "" Then
sMsg = sMsg & "You must provide a title for your announcement." & VbCrLf
nErr = 1
End If
If document.frmAddAnnouncement.txtBody.Value = "" Then
sMsg = sMsg & "You must provide a body for your announcement." & VbCrLf
nErr = 1
End If
Select Case nErr
Case 1
MsgBox sMsg,vbOKOnly,"Missing Information"
window.event.returnValue = False
Case Else
window.event.returnValue = True
End Select
Case Else
MsgBox "Not working"
window.event.returnValue = False

'Some other form code here
End Select
End Function
</Script>

When I view the source it is pulling the cookie and showing my form now but my select statement is completely ignored, none of my msgbox's come up even if the cases match? Any Ideas?
 
Select Case <%=request.cookies("frmName")%>

should be

Select Case "<%=request.cookies("frmName")%>"

otherwiser the select case statement is looking for a variable named frmAddAnnouncement and not the string value "frmAddAnnouncement"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top