If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > problems updating checkboxes in form

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-23-03, 15:13
ephemeralz ephemeralz is offline
Registered User
 
Join Date: Dec 2003
Posts: 20
Exclamation problems updating checkboxes in form

I'm having problems updating the checkboxes. Below is the code:

If Request("chkCount") > 0 Then
For i = 0 to Request("chkCount")
chkID = Request("display" & i)

If chkID <> "" Then
objConn.Execute("UPDATE Downloads SET display = 1 WHERE id = " & chkID)
Else
objConn.Execute("UPDATE Downloads SET display = 0 WHERE id = " & i)
End If
Next

sMsg = "Items have been successfully updated!"
End If

%>
<form name="form1" action="downloads.asp" method="POST">
<table border="0" cellpadding="0" cellspacing="0" width="414" >
<tr>
<td width="301">Select files: </td>
</tr>
<% rs.MoveFirst
While Not rs.EOF
iCount = iCount + 1
%>
<tr>
<td width="541"><input type="checkbox" name="display<%=iCount%>" value = "<%=rs("id")%>" <% if rs("display") Then Response.Write "CHECKED=True" End If%> ><%=rs("filename")%> - <%=rs("title")%></td>
</tr>
<% rs.MoveNext
Wend
%>
<input type="hidden" name="chkCount" value="<%=iCount%>">
<tr height="43">
<td height="43" colspan="3" width="474"><input type="submit" value="Select"><input type="reset"></td>
</tr>
</table>
</form>


When the a box is not check and I check it and click on the submit button, that record is updated. After it is checked, and when I try to uncheck it, the record is not updated. How can I update the record when the user unchecks the checkboxes?

Thanks!
Reply With Quote
  #2 (permalink)  
Old 12-23-03, 16:34
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
I'm not sure on this, it's been a while so forgive me if I'm wrong....

If you request a unchecked tick box the value that is returned will be null. You have to specifically use the isNull() function to check if the value is null (checking by using <> "" won't work).

Give that a try and see what happens.
Reply With Quote
  #3 (permalink)  
Old 12-24-03, 10:22
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
That should work - Try 2 things:

1. Find out if it is going to the wrong condition - Add a response.write for each condition to see which one is getting it.
2. If it is going to the wrong condition then response.write out the value of the checkbox with leading and trailing characters to see if there is a value given.
Reply With Quote
  #4 (permalink)  
Old 12-24-03, 12:14
gyuan gyuan is offline
Registered User
 
Join Date: Dec 2003
Posts: 454
the problem may be the counters

The two counters do not match. In the For ... Next loop, you used i starting with 0 to Request("chkCount"), but in the form, you placed iCount = iCount + 1 at the beginning of the While ... Wend loop. That means the starting number is 1 if iCount was initialized to 0. You may try to move iCount = iCount + 1 to the end of loop, which is before rs.MoveNext.
Reply With Quote
  #5 (permalink)  
Old 12-24-03, 21:05
rnealejr rnealejr is offline
Registered User
 
Join Date: Feb 2002
Posts: 2,232
As gyuan already mentioned, your counters are out of sink - but I think the problem is that your update statement uses 2 different variables to base the update:

objConn.Execute("UPDATE Downloads SET display = 1 WHERE id = " & chkID)
objConn.Execute("UPDATE Downloads SET display = 0 WHERE id = " & i)

When executing updates based on the same column - you need to keep the same variable. Your rs("id") holds the key to this - what are the values for rs("id") ? Your id value may be different from your counter value which could be causing the problem.

So zero base your iCount while loop or 1-base your for-next loop and change chkID to i for both update statements in the where clause.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On