Reply
Checking checkboxes with POST Array help
Old 01-05-2009, 11:06 PM Checking checkboxes with POST Array help
The PHP Professor

Posts: 328
Name: Alex
Location: Behind You
I have sort of a problem, i want to check all the check boxes on a page but with a POST array. So for example the name of the check box would be:

name="files[]"

So i would want this to work with an array using this simple code:

Code:
<!-- Begin
function checkAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = true ;
}

function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
	field[i].checked = false ;
}
//  End -->
__________________
Go Kirby! <(" . "<) (^" . "^) (>" . ")> Talkupation!
microcolt is offline
Reply With Quote
View Public Profile Visit microcolt's homepage!
 
When You Register, These Ads Go Away!
Old 01-06-2009, 08:53 AM Re: Checking checkboxes with POST Array help
wayfarer07's Avatar
Power Hungry Seamonkey

Posts: 2,630
Name: Abel Mohler
Location: Asheville, North Carolina USA
You can check a checkbox by updating its "checked" attribute.

Not sure what you mean by the POST array. As far as I'm aware, POST data is only sent to the server.

Code:
<script>
function checkAll(formId) {
var inputs = document.getElementById(formId).getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
     if (inputs[i].getAttribute("type") == "checkbox") {
          inputs[i].checked = true;
     }
}
}
function uncheckAll(formId) {
var inputs = document.getElementById(formId).getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
     if (inputs[i].getAttribute("type") == "checkbox") {
          inputs[i].checked = false;
     }
}
}
</script>
You'll need an id="whatever" attribute on the form in question, then pass this to the function.

Last edited by wayfarer07 : 01-06-2009 at 08:55 AM. Reason: fixed error in code
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to Checking checkboxes with POST Array help
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.06841 seconds with 12 queries