Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Just another Perl shrine
 
PerlMonks  

Re^3: OT? Checkbox list with CGI/Javascript

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re^2: OT? Checkbox list with CGI/Javascript
in thread OT? Checkbox list with CGI/Javascript

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

Replies are listed 'Best First'.
Re^4: OT? Checkbox list with CGI/Javascript
by rashley (Scribe) on Nov 11, 2005 at 13:30 UTC
    "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://507795]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.