Processing Checkboxes in ASP

Results 1 to 7 of 7

Thread: Processing Checkboxes in ASP

  1. #1
    Join Date
    Dec 1969
    Posts
    78

    Default Processing Checkboxes in ASP

    I know I posted this yest but I only got one reply and it realy wasnt what I was looking for so please help me.<BR>---------------------------------------------<BR>Hey guys I have a series of checkboxes with the same name eg: <BR><BR>&#060;input type="checkbox" name="gender" value="female"&#062; <BR>&#060;input type="checkbox" name="gender" value="male"&#062; <BR>&#060;input type="checkbox" name="gender" value="couple"&#062; <BR>&#060;input type="checkbox" name="gender" value="other"&#062; <BR><BR>Now I want to make sure that at least one of them are checked and the ones that are checked I want to assign a specific value say: 1 and the ones that arent I want to assign 0. <BR><BR>Now what I have so far doesnt work but just so you can get an idea of what I want to do here is the code: <BR><BR><BR>Dim arGender(4) &#039; array for gender you are looking for <BR>countGen = 0 <BR>For i=1 to Request.Form("gender").count &#039;loop from 1 to the number of gender tickbox items <BR>arGender(i) = 0 <BR>if Request.Form("gender")(i) = "on" Then &#039;if the option button is ticked then make is = 1 <BR>arGender(i) = 1 <BR>countGen = 1 <BR>response.write " <BR>" & countGen & " <BR>" <BR>End if <BR>Next <BR><BR>I thought this would work because I thought asp recognized all the checkboxes when saying Request.form("gender").count (should be 4) but what it does is recogize only the ones that are ticked. SO how can I do this so that it specifically recognizes (in an array) which one is which and which one is ticked and which one isnt. Without a bunch of if statements obviously. <BR><BR>To clear things up lets say I have this: <BR>&#060;input type="checkbox" name="gender" value="female"&#062; (checked) <BR>&#060;input type="checkbox" name="gender" value="male"&#062; <BR>&#060;input type="checkbox" name="gender" value="couple"&#062; (checked) <BR>&#060;input type="checkbox" name="gender" value="other"&#062; <BR><BR>Now I want ASP to recognize that female and couple are checked and assign a specific array spot for this and give it a value of 1, so this would be: <BR>dim argender(4) <BR>argender(0) = NULL <BR>argender(1) = 1 <BR>argender(2) = 0 <BR>argender(3) = 1 <BR>argender(4) = 0 <BR><BR>I hope this makes sense <BR>thanks for all your help <BR>Mike M <BR>

  2. #2
    IMRAN QURESHI Guest

    Default RE: Processing Checkboxes in ASP

    quick tip:<BR><BR>post your form using METHOD="GET", so that you can see what the form is passing..you MAY see all 4 checkbox items being posted along the querystring ! if only the CHECKED ones are being passed along the querystring, then you have to do some extra work on the server side code to fill in the gaps... :(

  3. #3
    Join Date
    Dec 1969
    Posts
    78

    Default RE: Processing Checkboxes in ASP

    Actually I am positive that only the checked ones are being passed I am now at the stage where I am doin some extra work server side ;) . However simply by outputing the Request.Form("gender").count I can tell the number of them that are passed. Pretty simple. Any other tips or suggestions? <BR>Thanks<BR>Mike M

  4. #4
    IMRAN QURESHI Guest

    Default RE: Processing Checkboxes in ASP

    Yes...<BR>i guess your treating checkboxes like radio buttons as a GROUP BUT theyre not so give them different names ! gender_m (gender male), gender_f (gender female) etc - so now youll have a variable for each checkbox and can qualify if a var is empty or not, hence retaining which actual checkboxe has been selected or not instead of a count ..<BR><BR>


  5. #5
    Join Date
    Dec 1969
    Posts
    152

    Default RE: Processing Checkboxes in ASP

    How about this.. <BR><BR>can you change the input boxes to this? ..<BR>&#060;input type="checkbox" name="gender0" value="female"&#062; <BR>&#060;input type="checkbox" name="gender1" value="male"&#062; <BR>&#060;input type="checkbox" name="gender2" value="couple"&#062;<BR>&#060;input type="checkbox" name="gender3" value="other"&#062;<BR><BR>ant then you can handle the request like...<BR><BR>dim argender(4)<BR><BR>for i = 0 to 3<BR><BR>if request.form("gender" & i) &#060;&#062; "" then<BR>argender(i) = 1<BR>else<BR>argender(i) = 0<BR>end if<BR><BR>next<BR><BR><BR>nathan@aspapp.com<BR><BR ><BR>

  6. #6
    Pete C Guest

    Default RE: Processing Checkboxes in ASP

    I think Nathan&#039;s suggestion is much simpler...you can even make it more generic with following:<BR><BR>&#060;input type="checkbox" name="gender0" value="Y"&#062; <BR>&#060;input type="checkbox" name="gender1" value="Y"&#062; <BR>&#060;input type="checkbox" name="gender2" value="Y"&#062; <BR>&#060;input type="checkbox" name="gender3" value="Y"&#062; <BR><BR>then <BR><BR>dim argender(4) <BR>dim currGender <BR><BR>for i = 0 to 3 <BR><BR>currGender = request.form("gender" & i)<BR> <BR>if currGender = "Y" then <BR> argender(i) = 1 <BR>else <BR> argender(i) = 0 <BR>end if <BR><BR>next <BR><BR>Hope that helps<BR><BR>Pete<BR>peterc8455@yahoo.com<BR><BR>

  7. #7
    Join Date
    Dec 1969
    Posts
    78

    Default RE: Processing Checkboxes in ASP

    got it to work like a charm with different names like all you guys mentionned. ASP deals with these checkboxes VERY poorly. They should be able to read both checked and no checked boxes. However thanks alot for all your help. This darn thing finally works.<BR><BR>Thanks<BR>Mike m

Posting Permissions

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