Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 340
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!
 
 
Register now for full access!
Old 01-06-2009, 09:53 AM Re: Checking checkboxes with POST Array help
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
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.
__________________
Join me on
Please login or register to view this content. Registration is FREE

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.19078 seconds with 12 queries