how do i get more than one checkbox being checked

Please support our ASP advertiser: 50% off 6 Months Dedicated Server Hosting from 1&1!
Reply

Join Date: Jul 2005
Posts: 41
Reputation: ohgosh is an unknown quantity at this point 
Solved Threads: 0
ohgosh's Avatar
ohgosh ohgosh is offline Offline
Light Poster

how do i get more than one checkbox being checked

 
0
  #1
Aug 22nd, 2005
HI there,

i haf a series of dynamic checkbox retrieved from db. I can display my checkbox successfully but now i cant get more than one checkbox being checked.

  1. <%
  2. sqlUser= "select distinct * from t_user_type order by userType"
  3. set rsUser = conn.execute(sqlUser)
  4.  
  5. do while not rsUser.eof
  6.  
  7. sqlView = "select * from t_email_view where emailID = '" & emailID & "' and emailView = '1' order by userType"
  8. set rsView = conn.execute(sqlView)
  9. %>
  10.  
  11. <tr>
  12. <td><input name="deleted" type="checkbox" value="<%=rsUser("userType")%>" <%if rsView("userType")=rsUser("userType") then response.Write(" checked")%> ><%=rsUser("userDesc")%></td>
  13. </tr>
  14. <%
  15. rsUser.moveNext
  16. loop
  17. %>
what's wrong with my code? how come only 1 checkbox is checked when there should be 2 checked checkboxes?

THANKS.
cheers,
ohgosh
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 520
Reputation: techniner is an unknown quantity at this point 
Solved Threads: 19
techniner techniner is offline Offline
Posting Pro

Re: how do i get more than one checkbox being checked

 
0
  #2
Aug 23rd, 2005
The problem is they have the same NAME

Your telling it

<input name="deleted" <--- So it loops through

So you need to dynamically rename these boxes.

maybe increment the variable like +1 and walk the loop giving each input a different name ?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 41
Reputation: ohgosh is an unknown quantity at this point 
Solved Threads: 0
ohgosh's Avatar
ohgosh ohgosh is offline Offline
Light Poster

Re: how do i get more than one checkbox being checked

 
0
  #3
Aug 23rd, 2005
so how should i do? any improvement on d code u could provide in here? sorry to bother u..

So you need to dynamically rename these boxes.
what do u mean? could u explain furthermore? thanks~
cheers,
ohgosh
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 520
Reputation: techniner is an unknown quantity at this point 
Solved Threads: 19
techniner techniner is offline Offline
Posting Pro

Re: how do i get more than one checkbox being checked

 
0
  #4
Aug 23rd, 2005
Originally Posted by ohgosh
HI there,

i haf a series of dynamic checkbox retrieved from db. I can display my checkbox successfully but now i cant get more than one checkbox being checked.

  1. <%
  2. sqlUser= "select distinct * from t_user_type order by userType"
  3. set rsUser = conn.execute(sqlUser)
  4.  
  5. do while not rsUser.eof
  6.  
  7. sqlView = "select * from t_email_view where emailID = '" & emailID & "' and emailView = '1' order by userType"
  8. set rsView = conn.execute(sqlView)
  9. %>
  10.  
  11. <tr>
  12. <td><input name="deleted" type="checkbox" value="<%=rsUser("userType")%>" <%if rsView("userType")=rsUser("userType") then response.Write(" checked")%> ><%=rsUser("userDesc")%></td>
  13. </tr>
  14. <%
  15. rsUser.moveNext
  16. loop
  17. %>
what's wrong with my code? how come only 1 checkbox is checked when there should be 2 checked checkboxes?
THANKS.
Well Do something like this

varcount=0

inside the loop do
varcount= varcount+1
namevar=deleted+varcount


<td><input name="& namevar &" blah blabvh

You follow?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 41
Reputation: ohgosh is an unknown quantity at this point 
Solved Threads: 0
ohgosh's Avatar
ohgosh ohgosh is offline Offline
Light Poster

Re: how do i get more than one checkbox being checked

 
0
  #5
Aug 23rd, 2005
do u mean this:

  1. <%
  2. i = 0
  3. varcount = 0
  4. sqlUser= "select * from t_user_type order by userType"
  5. set rsUser = conn.execute(sqlUser)
  6.  
  7. do while not rsUser.eof
  8. i = i + 1
  9. varcount = varcount + 1
  10. deleted = deleted + varcount
  11.  
  12. sqlView = "select * from t_email_view where emailID = '" & emailID & "' and emailView = '1' order by userType"
  13. set rsView = conn.execute(sqlView)
  14. %>
  15.  
  16. <tr>
  17. <td><input name="deleted" type="checkbox" value="<%=rsUser("userType")%>" <%if rsView("userType")=rsUser("userType") then response.Write(" checked")%> ><%=rsUser("userDesc")%></td>
  18. </tr>
  19. <%
  20. rsUser.moveNext
  21. loop
  22. %>
nothing happens, it is still the same..

i think something's wrong with my checking of checked checkboxes statement. it doesn't seem to loop thru the rsView("userType").

when i do a response.write in the <td> tag,

  1. <%response.Write(rsView("userType") & rsUser("userType"))%>
it gave me this:

Admin Admin
Admin Student
Admin Parent
Admin Teacher
Admin Principal

how and what should i do?
cheers,
ohgosh
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 131
Reputation: william_stam is an unknown quantity at this point 
Solved Threads: 2
william_stam's Avatar
william_stam william_stam is offline Offline
Junior Poster

Re: how do i get more than one checkbox being checked

 
0
  #6
Aug 24th, 2005
im seriously not following. where does the checkboxes come into it?


what do you hope to achieve???


you might want to change the name of the checkbox

if you pass it like that it would come out as ?deleted=1,2,3,4,5. which unless you right a split routine it wont help you.

<tr>
<td><input name="<%=deleted%>" type="checkbox" value="<%=rsUser("userType")%>" <%if rsView("userType")=rsUser("userType") then response.Write(" checked")%> ><%=rsUser("userDesc")%></td>
</tr>


surely there should be an endif there?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 41
Reputation: ohgosh is an unknown quantity at this point 
Solved Threads: 0
ohgosh's Avatar
ohgosh ohgosh is offline Offline
Light Poster

Re: how do i get more than one checkbox being checked

 
0
  #7
Aug 29th, 2005
heiya.. thanks william_stam!! saw so many of your replies & am grateful.. seems that you're quite pro in programmin ar?

anyw.. i use diff way to store my checkbox n the checking of the checkboxes by hard coding them and not retrieving frm db anymore.. i still have a Qn.. how do i validate them? validate to check that one of the checkbox must be checked in order to save the changes in the current page.

here are my checkbox codings
  1. <input type="checkbox" name="stud" value="yes">Student
  2. <input type="checkbox" name="lect" value="yes">Lecturer
  3. <input type="checkbox" name="principal" value="yes">Principal
  4. <input type="checkbox" name="admin" value="yes">Administrator
  5. <input type="checkbox" name="parent" value="yes">Parent
cheers,
ohgosh
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 8267 | Replies: 6
Thread Tools Search this Thread



Tag cloud for ASP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC