Reply
Checking checkboxes with POST Array help
Old 01-06-2009, 12:06 AM Checking checkboxes with POST Array help
The PHP Professor

Posts: 329
Name: Alex
Location: Behind You
Trades: 0
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, 09:53 AM Re: Checking checkboxes with POST Array help
wayfarer07's Avatar
NYE-KEE

Posts: 3,155
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
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.
__________________
Wayfarer | jQuery Tooltip Plugin | Mapbox: the jQuery Map
Freelance Jobs Available
If Google is the Coca-Cola of Web search, Bing is RC Cola

Last edited by wayfarer07; 01-06-2009 at 09: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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.12480 seconds with 13 queries