Results 1 to 18 of 18

Thread: dealing with multiple check boxes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    Unhappy dealing with multiple check boxes

    I'm pulling back a list of results whcih will include a checkbox, a listbox and a textbox.

    The idea is the user will tick rows that he wants an action performed, select the general reason from the listbox and write more specific information in the texbox.

    The user will be able to tick etc multiple rows befoer clicking submit.

    The problem is i'm not sure how to deal with submitting values for multiple rows. i don't know how i'll be able to say.

    'ok this row was ticked and this value selected from the list box and this text entered in the textbox, and then this row was selected with this value selected from the listbox and this text entered in the textbox' etc etc

  2. #2
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727
    pull them all through in the next stage and create an array. Then lop through with an if statement to see if there ticked

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405
    thanks for the reply davebat.

    i've tried doing the following. i've managed to determine and
    display whether the checkbox on a row is selected. (i think)
    but i also want to try and display the selection from the listbox and the textbox. but i'm not sure how to.

    Code:
    	dim TransferItemID
    	dim IsSelected
    
    	for each TransferItemID in Request.form
    		IsSelected = (Request.form(TransferItemID).count = 3)
    		if IsSelected then
    			response.write TransferItemID & " is selected " & IsSelected & "<br>"
    		else
    			response.write TransferItemID & " is not selected " & IsSelected & "<br>"
    		end if
    	next

  4. #4
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    This thread might help. I have provided a solution in this thread a while back.

    Have a look...

    http://www.vbforums.com/showthread.p...ghlight=danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405
    cheers for the reply. i've had a look at the example but it doesn't seem to be quite what i'm trying to do.

    i have three controls that can have stuff entered/selected.
    and when i submit i to be able to get the data for all of them where the checkbox is ticked.

  6. #6
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Post the code of the sbmiting page and i will give you a solution. I am not exactly sure what are you having problem withs. You say you can read the value of selected items. What part is not working..
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405
    this is the stuff for the posting page

    Code:
    private sub ShowProductForSubCode(TransferID)
    	Dim RejCon
    	Dim RejRes
    	Dim RejCmd
    	Dim RejParam
    	
    	set RejCon = CreateConnection("INTERNAL", "ilabelCustomers")
    	set RejRes = server.createobject("adodb.recordset")
    	set RejCmd = server.createobject("adodb.command")
    	RejCmd.commandtype = 4
    	RejCmd.commandtext = "spBTRGetProductToRejectByTID"
    
    	set RejParam = RejCmd.createparameter("@TransferID", 3,1)
    	RejCmd.parameters.append RejParam
    	RejParam.value = TransferID
    
    	set RejCmd.activeconnection = RejCon
    	set RejRes = RejCmd.execute
    
    	response.write "<center><table><form action='LogRejectedProducts.asp' method='post'><tr class='header'><th>SubCode</th><th>Ean</th><th>Product Description</th><th>Date Created</th><th>Transferid</th><th>Reject</th><th>Reason List</th><th>Specific Reason</th></tr>"
    	do while not RejRes.eof
    		response.write "<tr><td>" & RejRes.fields("smanucode").value & "</td><td>" & RejRes.fields("eancode").value & "</td><td>" & RejRes.fields("productdescription").value & "</td><td>" & RejRes.fields("datecreated").value & "</td><td>" & RejRes.fields("transferid").value & "</td><td><input type=checkbox name='" & RejRes.fields("transferitemid").value & "'>" 
    		'POPULATE A LIST BOX AGAINST EVERY ROW, done it with separate function
    		response.write "</td><td>" & GetRejectionList(RejRes.fields("transferitemid").value) & "</td><td>"
    		response.write "<input type=text name='" & RejRes.fields("transferitemid").value & "'></td></tr>"
    		RejRes.movenext 
    	loop
    
    	response.write "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td><input type='Submit' value='Reject'></td></form></table></center>"
    	RejCon.close
    	set RejCon = nothing
    	set RejCmd = nothing
    	set RejRes = nothing
    end sub
    
    private function GetRejectionList(TransferItemID)
    	Dim RejCon
    	Dim RejRes
    	Dim RejCmd
    	Dim OptionString
    	
    	set RejCon = CreateConnection("INTERNAL", "ilabelCustomers")
    	set RejRes = server.createobject("adodb.recordset")
    	set RejCmd = server.createobject("adodb.command")
    	RejCmd.commandtype = 4
    	RejCmd.commandtext = "spBTRGetRejectionList"
    
    	set RejCmd.activeconnection = RejCon
    	set RejRes = RejCmd.execute
    
    	OptionString = "<select name='" & TransferItemID & "'>"
    	do while not RejRes.eof
    		OptionString = OptionString & "<option selected value=" & RejRes.fields(0).value & ">" &  RejRes.fields(1).value & "</option>"
    		RejRes.movenext				
    	loop
    	GetRejectionList = OptionString
    
    	RejCon.close
    	set RejCon = nothing
    	set RejCmd = nothing
    	set RejRes = nothing
    end function
    at the moment this is all i've got for the receiving

    Code:
    	dim TransferItemID
    	dim IsSelected
    	dim tes
    
    	for each TransferItemID in Request.form
    		IsSelected = (Request.form(TransferItemID).count = 3)
    		test = (Request.form(TransferItemID).count =6)
    		if IsSelected then
    			response.write Transfer & " is selected " & IsSelected & "<br>"
    			response.write test
    		else
    			response.write TransferItemID & " is not selected " & IsSelected & "<br>"
    		end if
    	next
    what i want to be able to do is say.

    for all checked rows display the selection from the listbox and the contents of the textbox

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405
    arrgh this is doing my head in any help would be greatly appreciated

  9. #9
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Can you quickly pass me the generated HTML file too, that will be much easier for me, as i dont wanna go through the each asp code. Ill try to give u a solution now.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405
    Code:
    private sub ShowProductForSubCode(TransferID)
    	Dim RejCon
    	Dim RejRes
    	Dim RejCmd
    	Dim RejParam
    	
    	set RejCon = CreateConnection("INTERNAL", "ilabelCustomers")
    	set RejRes = server.createobject("adodb.recordset")
    	set RejCmd = server.createobject("adodb.command")
    	RejCmd.commandtype = 4
    	RejCmd.commandtext = "spBTRGetProductToRejectByTID"
    
    	set RejParam = RejCmd.createparameter("@TransferID", 3,1)
    	RejCmd.parameters.append RejParam
    	RejParam.value = TransferID
    
    	set RejCmd.activeconnection = RejCon
    	set RejRes = RejCmd.execute
    
    	response.write "<center><table><form action='LogRejectedProducts.asp' method='post'><tr class='header'><th>SubCode</th><th>Ean</th><th>Product Description</th><th>Date Created</th><th>Transferid</th><th>Reject</th><th>Reason List</th><th>Specific Reason</th></tr>"
    	do while not RejRes.eof
    		response.write "<tr><td>" & RejRes.fields("smanucode").value & "</td><td>" & RejRes.fields("eancode").value & "</td><td>" & RejRes.fields("productdescription").value & "</td><td>" & RejRes.fields("datecreated").value & "</td><td>" & RejRes.fields("transferid").value & "</td><td><input type=checkbox name='" & RejRes.fields("transferitemid").value & "'>" 
    		'POPULATE A LIST BOX AGAINST EVERY ROW, done it with separate function
    		response.write "</td><td>" & GetRejectionList(RejRes.fields("transferitemid").value) & "</td><td>"
    		response.write "<input type=text name='" & RejRes.fields("transferitemid").value & "'></td></tr>"
    		RejRes.movenext 
    	loop
    
    	response.write "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td><input type='Submit' value='Reject'></td></form></table></center>"
    	RejCon.close
    	set RejCon = nothing
    	set RejCmd = nothing
    	set RejRes = nothing
    end sub
    
    private function GetRejectionList(TransferItemID)
    	Dim RejCon
    	Dim RejRes
    	Dim RejCmd
    	Dim OptionString
    	
    	set RejCon = CreateConnection("INTERNAL", "ilabelCustomers")
    	set RejRes = server.createobject("adodb.recordset")
    	set RejCmd = server.createobject("adodb.command")
    	RejCmd.commandtype = 4
    	RejCmd.commandtext = "spBTRGetRejectionList"
    
    	set RejCmd.activeconnection = RejCon
    	set RejRes = RejCmd.execute
    
    	OptionString = "<select name='transfer'>"
    	do while not RejRes.eof
    		OptionString = OptionString & "<option selected value=" & RejRes.fields(0).value & ">" &  RejRes.fields(1).value & "</option>"
    		RejRes.movenext				
    	loop
    	GetRejectionList = OptionString
    
    	RejCon.close
    	set RejCon = nothing
    	set RejCmd = nothing
    	set RejRes = nothing
    end function
    html for form

    Code:
    <html>
    <head>
    	<link rel="stylesheet" type="text/css" href="include/styles.css">
    		<title>Transfered Images Available For Rejection</title>
    		<center>
    			<h2>Transfered Images Available For Rejection</h2>
    		</center>
    </head>
    <center><table><form action='LogRejectedProducts.asp' method='post'><tr class='header'><th>SubCode</th><th>Ean</th><th>Product Description</th><th>Date Created</th><th>Transferid</th><th>Reject</th><th>Reason List</th><th>Specific Reason</th></tr><tr><td>AAPP001</td><td>5000452003623</td><td>Geo Adams 20 Cooked Cocktail Pork Sausages 176g</td><td>15/12/03 12:13:00</td><td>195</td><td><input type=checkbox name='1699'></td><td><select name='1699'><option selected value=22>Rejected (Customer)</option><option selected value=21>Rejected (PH QA)</option></td><td><input type=text name='1699'></td></tr><tr><td>AAPP001</td><td>50452880</td><td>Geo Adams Lincolnshire Pork Sausages 454g</td><td>15/12/03 12:13:00</td><td>195</td><td><input type=checkbox name='1700'></td><td><select name='1700'><option selected value=22>Rejected (Customer)</option><option selected value=21>Rejected (PH QA)</option></td><td><input type=text name='1700'></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td><input type='Submit' value='Reject'></td></form></table></center>
    result of ticking one box and submitting

    Code:
    <html>
    1699 is selected True<br>1700 is not selected False<br>
    </html>

  11. #11
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    I meant the generated HTML output after the posting asp page has been parsed. Just run the posting asp page in your browser and click on view source and copy and paste the html out put here.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405
    i have, haven't i, above is the html that gen's the form and then underneath that is the results of posting the page

  13. #13
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by sagey
    i have, haven't i, above is the html that gen's the form and then underneath that is the results of posting the page
    Oops sorry, it was all in one line, and i skimme through it and missed it. Give me a while to go through the code and try to solve ur poblem. Ill get back to you.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405
    b rilliant cheers i've got the feeling i'm doing something really daft

  15. #15
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Ok here is the problem and a possible solution. I am sure it can be done in more then one ways, but here is my approach.

    You have named all the elements(checkbox, select box, textbox) same. It would be much easier if you use the following.

    Check the following in your submiting asp page.

    for checkbox
    name='cb" & transferitemid & "'"

    for textbox
    name='tb" & tranferitemid & "'"

    for list box
    name='lb" & transferitemid & "'"

    now try out my following code, i think thats what you asked for, if not then let me know.

    It will print out the value from the listbox and textbox for selected item.

    VB Code:
    1. <%
    2. dim TransferItemID
    3.     dim IsSelected
    4.  
    5.     for each TransferItemID in Request.form
    6.         IsSelected = Request.form(TransferItemID)
    7.  
    8.         dim n
    9.         n=mid(transferitemid,3)
    10.  
    11.         if IsSelected="on" then
    12.             response.write "TransferItemId :" & n & " "
    13.             response.write "listbox value :" & request.form ("lb" & n) & " "
    14.             response.write "textbox value :" &  request.form("tb" & n ) & "<br>"
    15.  
    16.         end if
    17.     next
    18.  
    19. %>

    Hope this helps.

    Danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  16. #16
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Output of the submiting file

    Code:
    <html>
    <head>
    	<link rel="stylesheet" type="text/css" href="include/styles.css">
    		<title>Transfered Images Available For Rejection</title>
    		<center>
    			<h2>Transfered Images Available For Rejection</h2>
    		</center>
    </head>
    <center><table><form action='LogRejectedProducts.asp' method='post'>
    <tr class='header'><th>SubCode</th><th>Ean</th><th>Product Description</th><th>Date Created</th>
    <th>Transferid</th><th>Reject</th><th>Reason List</th><th>Specific Reason</th></tr>
    <tr><td>AAPP001</td><td>5000452003623</td><td>Geo Adams 20 Cooked Cocktail Pork Sausages 176g</td>
    <td>15/12/03 12:13:00</td><td>195</td><td>
    
    <input type=checkbox name='cb1699'></td><td>
    <select name='sb1699'>
    <option selected value=22>Rejected (Customer)</option>
    <option selected value=21>Rejected (PH QA)</option></td>
    
    <td><input type=text name='tb1699'></td></tr><tr><td>AAPP001</td><td>50452880</td>
    <td>Geo Adams Lincolnshire Pork Sausages 454g</td><td>15/12/03 12:13:00</td><td>195</td><td>
    
    <input type=checkbox name='cb1700'></td><td><select name='sb1700'>
    <option selected value=22>Rejected (Customer)</option>
    <option selected value=21>Rejected (PH QA)</option></td><td>
    <input type=text name='tb1700'></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>
    <input type='Submit' value='Reject'></td></form></table></center>

    Here is the code which will process the file

    VB Code:
    1. <%
    2. dim TransferItemID
    3.     dim IsSelected
    4.  
    5.     for each TransferItemID in Request.form
    6.         IsSelected = Request.form(TransferItemID)
    7.  
    8.         dim n
    9.         n=mid(transferitemid,3)
    10.  
    11.         if IsSelected="on" then
    12.             response.write "TransferItemId :" & n & " "
    13.             response.write "listbox value :" & request.form ("lb" & n) & " "
    14.             response.write "textbox value :" &  request.form("tb" & n ) & "<br>"
    15.  
    16.         end if
    17.     next
    18.  
    19. %>
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405
    thanks for the reply. i think i almost get it. but i'm not sure how to go about using the

    for checkbox
    name='cb" & transferitemid & "'"

    i don't supose you could give me a code snippet of the the form should be like?

  18. #18
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Here you go

    VB Code:
    1. private sub ShowProductForSubCode(TransferID)
    2.     Dim RejCon
    3.     Dim RejRes
    4.     Dim RejCmd
    5.     Dim RejParam
    6.    
    7.     set RejCon = CreateConnection("INTERNAL", "ilabelCustomers")
    8.     set RejRes = server.createobject("adodb.recordset")
    9.     set RejCmd = server.createobject("adodb.command")
    10.     RejCmd.commandtype = 4
    11.     RejCmd.commandtext = "spBTRGetProductToRejectByTID"
    12.  
    13.     set RejParam = RejCmd.createparameter("@TransferID", 3,1)
    14.     RejCmd.parameters.append RejParam
    15.     RejParam.value = TransferID
    16.  
    17.     set RejCmd.activeconnection = RejCon
    18.     set RejRes = RejCmd.execute
    19.  
    20.     response.write "<center><table><form action='LogRejectedProducts.asp' method='post'><tr class='header'><th>SubCode</th><th>Ean</th><th>Product Description</th><th>Date Created</th><th>Transferid</th><th>Reject</th><th>Reason List</th><th>Specific Reason</th></tr>"
    21.     do while not RejRes.eof
    22.         response.write "<tr><td>" & RejRes.fields("smanucode").value & "</td><td>" & RejRes.fields("eancode").value & "</td><td>" & RejRes.fields("productdescription").value & "</td><td>" & RejRes.fields("datecreated").value & "</td><td>" & RejRes.fields("transferid").value & "</td><td>
    23.        
    24.         <input type=checkbox name='cb" & RejRes.fields("transferitemid").value & "'>"
    25.         'POPULATE A LIST BOX AGAINST EVERY ROW, done it with separate function
    26.         response.write "</td><td>" & GetRejectionList(RejRes.fields("transferitemid").value) & "</td><td>"
    27.        
    28.         response.write "<input type=text name='tb" & RejRes.fields("transferitemid").value & "'></td></tr>"
    29.         RejRes.movenext
    30.     loop
    31.  
    32.     response.write "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>
    33.     <input type='Submit' value='Reject'></td></form></table></center>"
    34.     RejCon.close
    35.     set RejCon = nothing
    36.     set RejCmd = nothing
    37.     set RejRes = nothing
    38. end sub
    39.  
    40. private function GetRejectionList(TransferItemID)
    41.     Dim RejCon
    42.     Dim RejRes
    43.     Dim RejCmd
    44.     Dim OptionString
    45.    
    46.     set RejCon = CreateConnection("INTERNAL", "ilabelCustomers")
    47.     set RejRes = server.createobject("adodb.recordset")
    48.     set RejCmd = server.createobject("adodb.command")
    49.     RejCmd.commandtype = 4
    50.     RejCmd.commandtext = "spBTRGetRejectionList"
    51.  
    52.     set RejCmd.activeconnection = RejCon
    53.     set RejRes = RejCmd.execute
    54.  
    55.     OptionString = "<select name='lb" & TransferItemId & "'>"
    56.     do while not RejRes.eof
    57.         OptionString = OptionString & "<option selected value=" & RejRes.fields(0).value & ">" &  RejRes.fields(1).value & "</option>"
    58.         RejRes.movenext            
    59.     loop
    60.     GetRejectionList = OptionString & "</select>"
    61.  
    62.     RejCon.close
    63.     set RejCon = nothing
    64.     set RejCmd = nothing
    65.     set RejRes = nothing
    66. end function
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width