kwilliams
06-09-2004, 03:27 PM
Hello,
I'm somewhat of a newbie to VBScript, so please keep that in mind. I've created a form that is going to be an "In/Out" board for a few employees. It simplay has 3 employees called "Tech's", and 2 radiobuttons by each name to that allows for them to log in and out. When they click on either radiobutton, the form automatically gets submitted, and the data gets inserted into a small DB table in SQL Server 2k.
My problem is in the actual form's radiobuttons that are located in a loop. If I name the radiobuttons "rbInOut", it does actually submit the "In" value to the DB table depending on the tech. But since the loop makes all of the radiobuttons keep the one name, I can't "check" the radiobutton as a display because they are all named the same.
So I tried having a number on the end of the RB's name (rbInOut1, rbInOut2, etc.), but then they wouldn't update the DB table. So I guess it's kind of the chicken & the egg problem.
Here's the code for my page, and maybe you see something that I'm missing in my code. Any help would greatly be appreciated. Thanks.
<%
Response.Buffer = True
Response.Write "</head><body>"
%>
<%
DIM strLogin, strUsername
strLogin = Request.ServerVariables("LOGON_USER")
'Capture everyting from position 10
strUsername = MID(strLogin, 10)
If strUsername = "" Then
Response.Redirect "http://SERVERNAME/HelpDesk/noaccess.asp"
End If
'The Form Selector:
Response.Write "<form name='techs' action='http://SERVERNAME/FOLDER/PAGENAME.asp' method='post'>"
Response.Write "<table width='150' border='0' bgcolor='#FFFFCC'><tr>"
sqlTech = "SELECT * FROM Tech_info ORDER BY Tech"
'------------------Database Query-----------------------
strConnectString = "Provider=SQLOLEDB; Data Source=SERVERNAME; Initial Catalog=DATABASENAME; User ID=USERID; Password=PW"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConnectString
Set objRS = Server.CreateObject("ADODB.RecordSet")
objRS.Open sqlTech, objConn
Response.Write "<td valign='top' width='150' colspan='3'>"
Response.Write "<strong>Help Desk - In/Out Board</strong><br></td></tr><tr>"
Response.Write "<td valign='top' width='100'>"
Response.Write "<strong>Technicians</strong></td>"
Response.Write "<td valign='top' width='25' align='center'>"
Response.Write "<strong>IN</strong></td>"
Response.Write "<td valign='top' width='25' align='center'>"
Response.Write "<strong>OUT</strong></td>"
While NOT objRS.EOF
'Looped radiobuttons
Dim strInOut
strInOut = objRS("InOut")
If strInOut = "In" Then
strStatus_In = " Checked"
strStatus_Out = ""
Else If strInOut = "Out" Then
strStatus_In = ""
strStatus_Out = " Checked"
End If
End If
'Dim strDBTech, strCount
'strDBTech = objRS("Tech")
'If strDBTech = "Tech1" Then
'strCount = "1"
'Else If strDBTech = "Tech2" Then
'strCount = "2"
'Else If strDBTech = "Tech3" Then
'strCount = "3"
'End If
'End If
'End If
Response.Write "<tr><td>" & objRS("Tech") & "</td>"
Response.Write "<td><input type='radio' name='rbInOut' value='" & objRS("Tech") & "_In' onClick='submit()'" & strStatus_In & "></td>"
Response.Write "<td><input type='radio' name='rbInOut' value='" & objRS("Tech") & "_Out' onClick='submit()'" & strStatus_Out & ">" & strInOut & "</td></tr>"
strInOut = Request.Form("rbInOut")
'Pass looped variables
strInOut = Request.Form("rbInOut")
If strInOut = "Tech1_In" Then
strTech = "Tech1"
strStatus = "In"
Else If strInOut = "Tech1_Out" Then
strTech = "Tech1"
strStatus = "Out"
End If
End If
If strInOut = "Tech2_In" Then
strTech = "Tech2"
strStatus = "In"
Else If strInOut = "Tech2_Out" Then
strTech = "Tech2"
strStatus = "Out"
End If
End If
If strInOut = "Tech3_In" Then
strTech = "Tech3"
strStatus = "In"
Else If strInOut = "Tech3_Out" Then
strTech = "Tech3"
strStatus = "Out"
End If
End If
objRS.MoveNext
Wend
Response.Write "<input type='hidden' name='hfUpdate' value='true'>"
objRS.Close
Set objRS = nothing
objConn.Close
Set objConn = nothing
'------------------End Database Query-------------------
'Update tech status
strForm = Request.Form("hfUpdate")
If strForm = "true" Then
'Update statement
sqlInOut = "UPDATE dbo.Tech_info SET InOut = '" & strStatus & "' WHERE Tech = '" & strTech & "'"
'------------------Database Query-----------------------
strConnectString = "Provider=SQLOLEDB; Data Source=SERVERNAME; Initial Catalog=DATABASENAME; User ID=USERID; Password=PW"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConnectString
Set objRS = Server.CreateObject("ADODB.RecordSet")
objRS.Open sqlInOut, objConn
Set objRS = nothing
Set objConn = nothing
Response.Write "<strong>Form Value: </strong>" & strStatus & "<br>"
Response.Write "<strong>Tech: </strong>" & strTech
End If
'------------------End Database Query-------------------
Response.Write "</td></tr></table></form>"
Response.Write "</table>"
Response.Write "</body></html>"
%>
I'm somewhat of a newbie to VBScript, so please keep that in mind. I've created a form that is going to be an "In/Out" board for a few employees. It simplay has 3 employees called "Tech's", and 2 radiobuttons by each name to that allows for them to log in and out. When they click on either radiobutton, the form automatically gets submitted, and the data gets inserted into a small DB table in SQL Server 2k.
My problem is in the actual form's radiobuttons that are located in a loop. If I name the radiobuttons "rbInOut", it does actually submit the "In" value to the DB table depending on the tech. But since the loop makes all of the radiobuttons keep the one name, I can't "check" the radiobutton as a display because they are all named the same.
So I tried having a number on the end of the RB's name (rbInOut1, rbInOut2, etc.), but then they wouldn't update the DB table. So I guess it's kind of the chicken & the egg problem.
Here's the code for my page, and maybe you see something that I'm missing in my code. Any help would greatly be appreciated. Thanks.
<%
Response.Buffer = True
Response.Write "</head><body>"
%>
<%
DIM strLogin, strUsername
strLogin = Request.ServerVariables("LOGON_USER")
'Capture everyting from position 10
strUsername = MID(strLogin, 10)
If strUsername = "" Then
Response.Redirect "http://SERVERNAME/HelpDesk/noaccess.asp"
End If
'The Form Selector:
Response.Write "<form name='techs' action='http://SERVERNAME/FOLDER/PAGENAME.asp' method='post'>"
Response.Write "<table width='150' border='0' bgcolor='#FFFFCC'><tr>"
sqlTech = "SELECT * FROM Tech_info ORDER BY Tech"
'------------------Database Query-----------------------
strConnectString = "Provider=SQLOLEDB; Data Source=SERVERNAME; Initial Catalog=DATABASENAME; User ID=USERID; Password=PW"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConnectString
Set objRS = Server.CreateObject("ADODB.RecordSet")
objRS.Open sqlTech, objConn
Response.Write "<td valign='top' width='150' colspan='3'>"
Response.Write "<strong>Help Desk - In/Out Board</strong><br></td></tr><tr>"
Response.Write "<td valign='top' width='100'>"
Response.Write "<strong>Technicians</strong></td>"
Response.Write "<td valign='top' width='25' align='center'>"
Response.Write "<strong>IN</strong></td>"
Response.Write "<td valign='top' width='25' align='center'>"
Response.Write "<strong>OUT</strong></td>"
While NOT objRS.EOF
'Looped radiobuttons
Dim strInOut
strInOut = objRS("InOut")
If strInOut = "In" Then
strStatus_In = " Checked"
strStatus_Out = ""
Else If strInOut = "Out" Then
strStatus_In = ""
strStatus_Out = " Checked"
End If
End If
'Dim strDBTech, strCount
'strDBTech = objRS("Tech")
'If strDBTech = "Tech1" Then
'strCount = "1"
'Else If strDBTech = "Tech2" Then
'strCount = "2"
'Else If strDBTech = "Tech3" Then
'strCount = "3"
'End If
'End If
'End If
Response.Write "<tr><td>" & objRS("Tech") & "</td>"
Response.Write "<td><input type='radio' name='rbInOut' value='" & objRS("Tech") & "_In' onClick='submit()'" & strStatus_In & "></td>"
Response.Write "<td><input type='radio' name='rbInOut' value='" & objRS("Tech") & "_Out' onClick='submit()'" & strStatus_Out & ">" & strInOut & "</td></tr>"
strInOut = Request.Form("rbInOut")
'Pass looped variables
strInOut = Request.Form("rbInOut")
If strInOut = "Tech1_In" Then
strTech = "Tech1"
strStatus = "In"
Else If strInOut = "Tech1_Out" Then
strTech = "Tech1"
strStatus = "Out"
End If
End If
If strInOut = "Tech2_In" Then
strTech = "Tech2"
strStatus = "In"
Else If strInOut = "Tech2_Out" Then
strTech = "Tech2"
strStatus = "Out"
End If
End If
If strInOut = "Tech3_In" Then
strTech = "Tech3"
strStatus = "In"
Else If strInOut = "Tech3_Out" Then
strTech = "Tech3"
strStatus = "Out"
End If
End If
objRS.MoveNext
Wend
Response.Write "<input type='hidden' name='hfUpdate' value='true'>"
objRS.Close
Set objRS = nothing
objConn.Close
Set objConn = nothing
'------------------End Database Query-------------------
'Update tech status
strForm = Request.Form("hfUpdate")
If strForm = "true" Then
'Update statement
sqlInOut = "UPDATE dbo.Tech_info SET InOut = '" & strStatus & "' WHERE Tech = '" & strTech & "'"
'------------------Database Query-----------------------
strConnectString = "Provider=SQLOLEDB; Data Source=SERVERNAME; Initial Catalog=DATABASENAME; User ID=USERID; Password=PW"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConnectString
Set objRS = Server.CreateObject("ADODB.RecordSet")
objRS.Open sqlInOut, objConn
Set objRS = nothing
Set objConn = nothing
Response.Write "<strong>Form Value: </strong>" & strStatus & "<br>"
Response.Write "<strong>Tech: </strong>" & strTech
End If
'------------------End Database Query-------------------
Response.Write "</td></tr></table></form>"
Response.Write "</table>"
Response.Write "</body></html>"
%>