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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox maintain state

Status
Not open for further replies.

secondreckoned

Technical User
Jan 20, 2004
35
CA
Hi,
I have a looped form that I am using to update a db, the form displays each record on a line and at the end of each line is a submit button to 'approve' the record. I would like to add a checkbox to each line that if checked will identify that record as denied write in the text field on the line "Denied". I am having trouble maintaining the stat of the checkbox so that it stays checked once the submit button is pressed, and then updating the db text field with denied. Below is the code to try to help clarify what i'm talking about. Thanks for any help.

if request.form.count > 1 then
'form has been submitted from admin.asp

if request.querystring("npa") <> "" then

wID = request.form("ID")
wApproval = Ucase(request.Form(Trim("wApproval")))
wHour = Clng(request.form("Hour"))
wMinutes = Clng(request.form("Minutes"))
wDetails = request.form(Ucase((Trim("Details"))))
'wDenied = request.form("Denied")
' If wDenied = "on" then
' wChecked = "checked"
' else
' wDenied = "unchecked"
' end if
DOW = wHour + wMinutes

Set updateRS = Server.CreateObject("ADODB.Recordset")
wUpdate = ("SELECT TOP 1 * FROM tb_WOW WHERE ID = '"&wID&"'")
updateRS.Open wUpdate, sConnect, 3, 3

updateRS.MoveFirst
updateRS("Details") = wDetails
updateRS("DOW") = DOW
updateRS("Mgr_apprd") = wApproval

updateRS.Update
updateRS.MoveFirst

updateRS.Close
Set updateRS = Nothing
else
'form from admin page was submitted this is done to maintain the npa from the original post from the form admin.asp
'Once the submit button is hit admin redirects here with npa, once it is up dated a variable is created called npa,
'this way the npa is populated in the querystring when update button is hit.
npa = request.form("npa")
end if
end if
End If
'create rs to display current records
if npa = "" then
npa = request.querystring("npa")
end if
Set npaRS = Server.CreateObject("ADODB.Recordset")
npa_query = ("SELECT * FROM tb_WOW WHERE NPA = '"& npa &"' AND MONTH(WowDate) = MONTH(GETDATE()) ORDER BY WowDate, WowTime")
npaRS.Open npa_query, sConnect, 3, 3

IF npaRS.EOF Then
no_records = "No Records Exist For Selected NPA<br><br>"
End If
%>
<% Counter = 1
bgcolor = "#F4F4F4"
Do until npaRS.EOF
Dim Counter

%>
<form method="post" name="update" action="Wow_npa.asp?npa=<%=npa %>">

<tr bgcolor="<%=bgcolor%>">
<% If bgcolor = "#F4F4F4" Then
bgcolor = "#FFCC33"
Else
bgcolor = "#F4F4F4"
End If
%>
<td align="center">
<%=(Counter)%>
</td>
<td>
<%=npaRS("WowDate")%>
</td>
<td>
<%=FormatDateTime(npaRS("WowTime"), vbShortTime)%>
</td>
<td>
<%=npaRS("TechID")%>
</td>
<td>
<%=npaRS("Manager")%>
</td>
<td>
<%=npaRS("Associate")%>
</td>
<td>
<%=npaRS("NPA")%>
</td>
<td>
<%=npaRS("DA")%>
</td>
<td>
<input type="text" size="15" maxlength="20" name="Details" value="<%=npaRS("Details")%>"></input>
</td>
<td nowrap>
<select name="Hour">
<option value="0">0</option>
<option value="60">1</option>
<option value="120">2</option>
<option value="180">3</option>
<option value="240">4</option>
<option value="300">5</option>
<option value="360">6</option>
<option value="420">7</option>
<option value="480">8</option>
<option value="540">9</option>
</select>
<select name="Minutes">
<option value="00">:00</option>
<option value="15">:15</option>
<option value="30">:30</option>
<option value="45">:45</option>
</select>
</td>
<td nowrap>
<%
LineTime = npaRS("DOW")

temp_elapsed = LineTime
time_diff = cLng(temp_elapsed)


time_days = fix(time_diff/60/24)
time_diff = time_diff - (time_days * 60 * 24)

time_hours = fix(time_diff/60)
time_diff = time_diff - (time_hours * 60)

if time_days > 0 then
elapsed_time = time_days & "D "
end if

if time_hours > 0 then
elapsed_time = elapsed_time & time_hours & "H "
end if

if time_diff > 0 then
elapsed_time = elapsed_time & time_diff & "M"
end if




response.write(elapsed_time)
elapsed_time = ""
temp_minutes = 0
temp_hours = 0

%>
</td>
<td>
<input type="text" maxlength="20" size="15" name="wApproval" value="<%=npaRS("Mgr_apprd")%>">
</td>
<td>
<input type="checkbox" name="Denied" <% if request.form("Denied") = "on" then
Response.Write " checked=""checked"""
end if %>
/>
</td>
<td>
<input type="submit" name="submit">
</td>
</tr>
<td>
<input type="hidden" name="ID" value="<%=npaRS("ID")%>">
</td>
</form>
<%
Counter = Counter + 1
npaRS.MoveNext

Loop
%>
 
When a checkbox is checked it passes it's value in the form post, when it is not checked it doesn't pass it's value. So basically what you need to do is something like:
Code:
<input type="checkbox" name="Denied" [highlight]value="on"[/highlight] <% if request.form("Denied") = "on" then
   Response.Write " checked=""checked"""
end if %>

Now you should be able to track it's state.

-T

barcode_1.gif
 
Hi Tarwn,
I added this code and it worked, thanks for your help:

<td>
<% denied = npaRS("Denied") %>
<input type="checkbox" name="Denied" value="ON" <% if denied = "ON" then response.write("checked") %>>
</td>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top