473,657 Members | 2,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check/Uncheck all checkboxes with name as 'name[]'

Hi, since sometime I'm stuck in a problem where I want to check or
uncheck all the checkboxes. If I'm choosing name for the checkbox
array as 'chkbx_ary' then I'm able to check/uncheck all the checkboxes
(code pasted below). But if name of the checkbox array is
'chkbx_ary[]' then it's failing. I want the name to be 'chkbx_ary[]'
because I want to access this array at server side.
Though one may not require to see php part but I'm still pasting the
code.

<script language="JavaS cript" type="text/javascript">
function CheckAll(field)
{
for (loop=0; loop < field.length; loop++)
{
field[loop].checked = true;
}
}

function UnCheckAll(fiel d)
{
for (loop=0; loop < field.length; loop++)
{
field[loop].checked = false;
}
}
</script>

<?php
echo '<form name="TestSelec t_Form" method="GET" action="TestLis t.php"
enctype="text/plain" style="margin:0 px">
<input type="radio" name="SelectOrN ot" value="Select_A ll"
onClick="CheckA ll(document.Tes tSelect_Form.Se lectModule)"
style="position :absolute;left: 290px;top:140px ;z-index:6">
<input type="radio" name="SelectOrN ot" value="Uncheck_ All"
onClick="UnChec kAll(document.T estSelect_Form. SelectModule)" checked
style="position :absolute;left: 400px;top:140px ;z-index:7">';
$file_name = "CONF/testselect.txt" ;
$fp_TstSlct = fopen("$file_na me", "r") or die("Some error occurred
while opening 'testSelect.txt ");
$TopPos = 170;
while(!feof($fp _TstSlct))
{
$TstSlct_data = fgets($fp_TstSl ct);
preg_match_all( "/([#]*)(.*)\s(\d+)\s *[;#]*(.*)/", $TstSlct_data,
$match, PREG_PATTERN_OR DER);
if ( $match[2][0] != NULL ) { //Checking whether module is present
or not. May be only comments have been put. For. e.g.
############### ####DSL HOME#########
if ( $match[1][0] == NULL ) { //Checking if line is starting with
'#' or not
echo '<input type="checkbox" name="SelectMod ule[]" value=' .
$match[2][0] . ' checked="checke d" style="position :absolute;left:
90px;top:' . $TopPos . 'px">';
} else {
echo '<input type="checkbox" name="SelectMod ule[]" value=' .
$match[2][0] . ' style="position :absolute;left: 90px;top:' . $TopPos .
'px">';
}

echo '<div id="text3" style="position :absolute; overflow:hidden ;
left:130px; top:' . $TopPos . 'px; width:79px; height:16px"><d iv
class="wpmd">';
echo '<div><font face="Arial">' . $match[2][0] . '</font></div>';
echo '</div></div>';

$TopPos = $TopPos + 25;
}
}
fclose($fp_TstS lct);

echo '<input name="Configure TestList" type="submit" value="Next"
style="position :absolute;left: 326px;top:403px ;z-index:16">
</form>

<div id="text1" style="position :absolute; overflow:hidden ; left:
265px; top:118px; width:69px; height:18px; z-index:9"><div
class="wpmd">
<div><font class="ws12" face="Arial">Se lect All</font></div>
</div></div>

<div id="text2" style="position :absolute; overflow:hidden ; left:
371px; top:118px; width:85px; height:18px; z-index:10"><div
class="wpmd">
<div><font class="ws12" face="Arial">Un check All</font></div>
</div></div>';
?>

Please someone suggest the solution as I'm totally stuck.
Thanks a lot in advance.
Oct 28 '08 #1
1 5177
SAM
Le 10/28/08 5:53 PM, Anuj a écrit :
Hi, since sometime I'm stuck in a problem where I want to check or
uncheck all the checkboxes. If I'm choosing name for the checkbox
array as 'chkbx_ary' then I'm able to check/uncheck all the checkboxes
(code pasted below). But if name of the checkbox array is
'chkbx_ary[]' then it's failing. I want the name to be 'chkbx_ary[]'

document.forms[0].elements['chkbx_ary[]'];

document.forms['TestSelect_For m'].elements['chkbx_ary[]'];

if several checkboxes of same name
that will return [object NodeList]

ordinary checboxes don't wear same name ...
how do you recognize one from the other ?

some tests :

var chc = document.forms['TestSelect_For m']['chkbx_ary[]'];
alert( chc[0].value);
alert( document.forms['TestSelect_For m']['chkbx_ary[]'][0].value );
for(var i=0, n=chc.length; i<n; i++)
alert(chc[i].value)
var t = '';
for(var i=0, n=chc.length; i<n; i++)
t += chc[i].name + '\'s value = ' + chc[i].value +'\n';
alert(t);

because I want to access this array at server side.
Though one may not require to see php part but I'm still pasting the
code.
onclick="CheckA ll(document.Tes tSelect_Form['SelectModule[]'])
or (because it is in the form) :
onclick="CheckA ll(this.form['SelectModule[]']);
<script language="JavaS cript" type="text/javascript">
function CheckAll(field)
{
for (loop=0; loop < field.length; loop++)
{
field[loop].checked = true;
}
}

function UnCheckAll(fiel d)
{
for (loop=0; loop < field.length; loop++)
{
field[loop].checked = false;
}
}
</script>

<?php
please give the result in html !

where is the problem ? which line(s) ?
Please someone suggest the solution as I'm totally stuck.
Thanks a lot in advance.
You can't use :
document.TestSe lect_Form.chkbx _ary[]
because brackets are of JS language
so you'll do :
document.TestSe lect_Form.eleme nts['chkbx_ary[]']
or :
document.getEle mentsByName('ch kbx_ary[]');
to get the collection of checkboxes named 'chkbx_ary[]'
--
sm
Oct 28 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
6611
by: Mike Lopez | last post by:
Hello. I need to set a checkbox to the "checked" state and prevent the user from unchecking it. I tried using "disabled", but then the value is not passed on the Post to an ASP page. Anyone have any ideas? Thanks in advance,
8
2473
by: pw | last post by:
Hi, I need to create a function in javascript to check or uncheck all checkboxes in a form. From what I understand, I can do this either by specifying the name of the check box fields such as: function checkAll(list) { var o = document.getElementById(list); var c = o.checked; var f = document.forms.f; var a = f.item(list);
2
3587
by: Chris Davoli | last post by:
How do you enable a check box in the GridView. I selected Checkbox Field in the Columns of the GridView, and the check box shows up in the Grid view, but it is disabled. How do I enable it so I can check/uncheck it. Also, what event do I use to check it for a value? Any articles out there? -- Chris Davoli
10
5195
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named 'CheckAllRows' on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the...
4
11682
by: chengsi | last post by:
Hi, I have a "continuous" subform which is linked to a table which has a checkbox field. I would like to create a Check All/Uncheck All checkbox control that both checks and disables the checkboxes in the subform. At the moment I can disable/enable all textboxes, however my coding only checks/unchecks the FIRST checkbox in the subform, and ignores the other checkboxes in the list. My current VBA code is: Private Sub...
12
4041
by: swebster | last post by:
I need to zero in on a specific section of my jsp form during a hide to uncheck the checkboxes in that section. Currently, anything I try either unchecks all checkboxes on the form or doesn't work at all. When I associated the specific section with ID the first box within the div is unchecked but not the second. Suggestions? <div id="menu1" class=hide> <div id="col1"> <input type="checkbox" name="Topic" value="_topic1"...
3
2825
by: Ryanfromscotland | last post by:
Hey there everyone, this is my first post so be nice :-) I have wrote quite a bit so the actual question is written out at the end if you want to skip on and see if you can answer it without the rest of the info. I'm a hobbiest programmer and have taken up the project of writing a savestate editor - if you don't know what that is it's not really important - but I am having a bit of trouble with some code and google isn't turning up the answer...
3
3359
by: BibhuAshish | last post by:
Hi, I want to check or uncheck a number of checkboxes by clicking an image. My html code is given below: <TABLE> <TR> <TD>
13
3067
by: PhpCool | last post by:
Hi, since sometime I'm stuck in a problem where I want to check or uncheck all the checkboxes. If I'm choosing name for the checkbox array as 'chkbx_ary' then I'm able to check/uncheck all the checkboxes (code pasted below). But if name of the checkbox array is 'chkbx_ary' then it's failing. I want the name to be 'chkbx_ary' because I want to access this array at server side. Though one may not require to see php part but I'm still pasting...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.