Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: OT? Checkbox list with CGI/Javascript

by ickyb0d (Monk)
on Nov 11, 2005 at 17:05 UTC ( [id://507785]=note: print w/replies, xml ) Need Help??


in reply to OT? Checkbox list with CGI/Javascript

on that page you could have a hidden field called "all_checkboxes" or something. using various javascript and DOM stuff, you can get the values of the checkboxes (note: JS code below is just pseudo-code). on the onSubmit event, populate that field with something like...
for(var i=0; i<total_checkboxes; i++) { if(checkbox = 'checked') { all_checkboxes.value += userid + '|||'; } }
before the submit occours, that field should look something like "2|||3|||8|||20|||". Only filled with the checked userids.

then in your cgi script, split that field using a split command...
my @userids = split('|||', $cgi->param('all_checkboxes');

Replies are listed 'Best First'.
Re^2: OT? Checkbox list with CGI/Javascript
by rashley (Scribe) on Nov 11, 2005 at 17:18 UTC
    Right, this is along the lines of what I was thinking.

    How does your IF statment above reference WHICH checkbox it's looking at, though. This is the part I can't figure out.

    Calculating the value for total_checkboxes is also going to be an issue.

      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

        "populating an array (user_ids for example), then giving that to the javascript via a template variable."

        Hmm.. and how do I do that?

        I've tried:

        <input type="hidden" name="userArray" value=@userids>
        And then:
        var users = userForm.userArray;
        In the java, then referring to users.length, but it's returning undefined.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://507785]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found