Checkbox & Arrays

Results 1 to 2 of 2

Thread: Checkbox & Arrays

  1. #1 Guest

    Default Checkbox & Arrays

    I&#039m populating a form with a number of checkboxes, which is unknown (note my use of arrays):<BR><BR>Dim chkKeywords(50)<BR>DO while NOT objRSr.EOF<BR>intX = intX + 1<BR>%&#062;<BR>&#060;input type="checkbox" class="one" name="&#060;%= "chkKeywords(" & intX & ")" %&#062;" value="&#060;%=objRSr("IPickkey") %&#062;"&#062; &#060;%=objRSr("CDesc")%&#062;<BR><BR>&#060;%<BR>o bjRSr.MoveNext<BR>LOOP<BR>objRSr.Close<BR>Set objCmd = Nothing<BR>Set objParam = Nothing<BR><BR>Then, this is how i am trying to evaluate the values of each checkbox selected, kinda like a visual trace:<BR>FOR p = 0 to intX<BR>response.write (CInt(chkKeywords(p))) & p & "<BR>"<BR>Next<BR><BR>The output i get is akin to...<BR>0 1<BR>0 2<BR>0 3<BR>0 4<BR>0 5<BR>0 6<BR>0 7<BR><BR>Any help, and any kind critique of my code, is always welcome.<BR>"Remember, mean people won&#039t inherit planet Earth. They&#039ll just work there."<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default No sense to me...what are you trying to do?

    Have you tried doing a "View &#124 Source" of the resultant HTML in the browser? <BR><BR>Have you actually *looked* at what this line is producing?<BR><BR>&#060;input type="checkbox" class="one" name="&#060;%= "chkKeywords(" & intX & ")" %&#062;" value="&#060;%=objRSr("IPickkey") %&#062;"&#062; &#060;%=objRSr("CDesc")%&#062;<BR><BR>Try it. <BR><BR>Unless I misread it, you will be generating something like this in the HTML:<BR><BR>&#060;input type="checkbox" class="one" name="chkKeywords(13)" value="P13QY"&#062; Striped pajamas<BR><BR>(where, of course, the P13QY and Striped pajamas are made up, just for illustrative purposes).<BR><BR>Now, there is nothing inherently wrong with that. It is perfectly legal to name any form field with virtually any characters you wish, including putting parentheses into the name.<BR><BR>But I doubt seriously that you are doing what you thought you were doing.<BR><BR>Certainly there is no automatic connection between the names of these checkboxes and the *just-happens-to-be-named-the-same* array in your ASP code.<BR><BR>So you send the HTML code off to the browser. The user clicks on some of the checkboxes. The form posts back to some other ASP page. What has that array got to do with *anything*? It won&#039t be "remembered" either the HTML or the next ASP page.<BR><BR>And you say you are trying to evaluate the checkboxes selected. Do you mean you are trying to do that in the same ASP page? I hope you are aware the page must be sent to the browser, the checkboxes checked (or not), and then the results evaluated on another ASP page?<BR><BR>Well, I am pretty mystified about what you were trying to accomplish, unless you were simply trying to get the values of the checked checkboxes when the form is submitted. But if that is what you wanted...<BR><BR>Are you aware that checkboxes that are *not* checked will *not* appear at the next form, *at all*? So you don&#039t *have* to "keep track" of which ones are checked. If they aren&#039t checked, they won&#039t show up. Period.<BR><BR>Do you have *OTHER* data on this form, such that each checkbox needs to be associated with that data? If so, ask again. If not, maybe all you need is this code???<BR><BR>&#060;%<BR>&#039 on the first page...<BR>DO while NOT objRSr.EOF<BR>&nbsp;&nbsp;&nbsp; Response.Write "&#060;INPUT Type=&#039Checkbox&#039 Class=&#039one&#039 Name=&#039CB&#039 " _<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; & " Value=&#039" & objRSr("IPickkey") & "&#039&#062;" & objRSr("CDesc") & vbNewLine<BR>&nbsp;&nbsp;&nbsp; objRSr.MoveNext<BR>Loop<BR>%&#062;<BR><BR>******** ***********<BR><BR>&#060;%<BR>&#039 on the page the form posts to:<BR>&#039<BR>For Each Item In Request.Form("CB")<BR>&nbsp;&nbsp;&nbsp; Response.Write "user checked " & Item & "&LT;BR&#062;" & vbNewLine<BR>Next<BR>%&#062;<BR><BR>or you can just do<BR><BR>&#060;% = Request.Form("CB") %&#062;<BR><BR>to see all the choices in a comma-space delimited list.<BR><BR>Or or or or...<BR><BR>************<BR><BR>If this is not what you were trying to do, then maybe you need to explain. I certainly can&#039t see how the code you posted will do what you want. But maybe you are doing something exotic? <BR><BR>

Posting Permissions

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