W3Schools is going to be your best friend, especially if you're just getting started with JS. I haven't tested this but it would most likely look something like this...

var checked_boxes = ""; for(var i=0; i<total_checkboxes; i++) { var cur_box = document.getElementById('userbox_' + i); if(cur_box.checked) { checked_boxes += i + '|||'; } } var all_checkboxes = document.getElementById('all_checkboxes'); all_checkboxes.value = checked_boxes;

now this is assuming all of your userid's are 0,1,2,3,... and the checkbox names are setup with the name/id as 'userbox_0', 'userbox_1', 'userbox_2',... i'm also guessing that you're user id's won't be consecutive like that. you might try populating an array (user_ids for example), then giving that to the javascript via a template variable. once that array is stored in js, you could just use user_ids.length for the total_checkboxes and just use user_ids[i] to reference the user id stored in the array.

you might also want to look at the JSON perl module as well for transferring data to and from javascript applications. this might be confusing at the time if you're just using javascript, but you can find more information at json.org


In reply to Re^3: OT? Checkbox list with CGI/Javascript by ickyb0d
in thread OT? Checkbox list with CGI/Javascript by rashley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.