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: <%=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="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: </td><td><input name="txtTitle" type="text" size="75" maxlength="75" value="<%=RS.Fields("Subject")%>"></td>
</tr>
<tr>
<td valign="Top">Body: </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?
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: <%=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="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: </td><td><input name="txtTitle" type="text" size="75" maxlength="75" value="<%=RS.Fields("Subject")%>"></td>
</tr>
<tr>
<td valign="Top">Body: </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?