Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

CheckBox Maintain State

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
%>
0
marcus72
Asked:
marcus72
  • 2
1 Solution
 
WMIFCommented:
you dont have a value set in that checkbox.

<input type="checkbox" name="Denied" <% if request.form("Denied") = "on" then
                                                                      Response.Write " checked=""checked"""
                                                                 end if %>
               />


should be:
<input type="checkbox" name="Denied" value="on" <% if request.form("Denied") = "on" then
                                                                      Response.Write " checked=""checked"""
                                                                 end if %>
               />
0
 
WMIFCommented:
also, you have a hidden field in a table cell outside the row.

          <td>
               <input type="submit" name="submit">
          </td>
     </tr>
     <td>
               <input type="hidden" name="ID" value="<%=npaRS("ID")%>">
     </td>
</form>


i would just drop that hidden field beside the submit button and remove that cell:
          <td>
               <input type="submit" name="submit">
               <input type="hidden" name="ID" value="<%=npaRS("ID")%>">
          </td>
     </tr>
</form>


but you could also just move the row tag so the cell is inside:
          <td>
               <input type="submit" name="submit">
          </td>
     <td>
               <input type="hidden" name="ID" value="<%=npaRS("ID")%>">
     </td>
     </tr>
</form>
0
 
marcus72Author Commented:
I added a varchar field to my db called 'denied' and used the code
<td><% denied = npaRS("Denied") %>
                  <input type="checkbox" name="Denied" value="ON" <% if denied = "ON" then   response.write("checked") %>>
</td>      

wDenied = request.form("Denied")

This worked for me.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now