473,549 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to check all the checkboxes if checkbox name is '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
13 3056
PhpCool wrote:
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.
How about?
obj = document.getEle mentsByName('ch kbx_ary[]'); obj[i].value=somethin g;

I know this works because in one of my apps I have "n" similar rows, all
with checkboxes named cond[] (for the same reason -- php). I have a
clear button at the end of each row where I call a javascript function
passing in the id number, i. In that function I use:

obj = document.getEle mentsByName('co nd[]'); obj[i].value=0;

It should be a simple matter for you to do:

obj = document.getEle mentsByName('ch kbx_ary[]');
for (i=0; i<obj.length; i++) {
obj[i].value = something;
}
Oct 28 '08 #2
PhpCool wrote:
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.
The characters [ and ] aren't valid in a name. You can use a-z, A-Z and
0-9 and underscore. That's it.
Oct 28 '08 #3
On 2008-10-28 13:29, Stevo wrote:
The characters [ and ] aren't valid in a name. You can use a-z, A-Z and
0-9 and underscore. That's it.
If you're talking about the HTML "name" attribute, that's not correct.
The content of "name" is defined as cdata, which includes the square
brackets. <input name="box[]" type="checkbox" value="foo"is valid.

If you're talking about ECMAScript identifiers, it's not correct either.
According to the standard, almost any Unicode letter (or corresponding
escape sequence) can be used in an Identifier:

Identifier ::
IdentifierName but not ReservedWord

IdentifierName ::
IdentifierStart
IdentifierName IdentifierPart

IdentifierStart ::
UnicodeLetter
$
_
\ UnicodeEscapeSe quence

UnicodeLetter
any character in the Unicode categories “Uppercase letter (Lu)”,
“Lowercase letter (Ll)”, “Titlecase letter (Lt)”,
“Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number
(Nl)”.
This is valid ECMAScript:

var привет = "hello";
alert(прив т);

I found that rather surprising, but it appears to work at least in
Firefox and Opera, and in Rhino:

jsvar привет = "hello";
jsprint(при ет);
hello

It does not work with the SpiderMonkey jsshell:

jsvar привет = "hello";
typein:1: SyntaxError: illegal character:
typein:1: var привет = "hello";
typein:1: .....^
jsvar hélłö = "hello";
typein:2: SyntaxError: illegal character:
typein:2: var hélłö = "hello";
typein:2: ......^
So, all in all it's probably not a good idea to rely on it, and stick to
ASCII characters in identifiers.
- Conrad
Oct 28 '08 #4
On Oct 28, 7:29*am, Stevo <n...@mail.inva lidwrote:
The characters [ and ] aren't valid in a name. You can use a-z, A-Z and
0-9 and underscore. That's it.
That's an old misunderstandin g, dis-proven many times. Please don't
keep spreading it.

Matt Kruse
Oct 28 '08 #5
Conrad Lender wrote:
On 2008-10-28 13:29, Stevo wrote:
>The characters [ and ] aren't valid in a name. You can use a-z, A-Z and
0-9 and underscore. That's it.

[...]
If you're talking about ECMAScript identifiers, it's not correct either.
According to the standard, almost any Unicode letter (or corresponding
escape sequence) can be used in an Identifier:
That's nonsense, at best misleading.
Identifier ::
IdentifierName but not ReservedWord

IdentifierName ::
IdentifierStart
IdentifierName IdentifierPart

IdentifierStart ::
UnicodeLetter
$
_
\ UnicodeEscapeSe quence

UnicodeLetter
any character in the Unicode categories “Uppercase letter (Lu)”,
“Lowercase letter (Ll)”, “Titlecase letter (Lt)”,
“Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number
(Nl)”.
Note that "[" and "]" do _not_ occur and are _not_ contained in the
mentioned Unicode subsets; only letters are allowed for good reason. You
may include these characters in identifiers escaped as \u005b and \u005d,
but not as they are. A wise design decision, otherwise

f[oo]][][][b][a][r][]]

would confuse the hell out of the parser ;-)
This is valid ECMAScript:

var привет = "hello";
alert(прив т);

I found that rather surprising, but it appears to work at least in
Firefox and Opera, and in Rhino:
[...]
It does not work with the SpiderMonkey jsshell:

jsvar привет = "hello";
typein:1: SyntaxError: illegal character:
typein:1: var привет = "hello";
typein:1: .....^
[...]
So, all in all it's probably not a good idea to rely on it,
It *might not* be a good idea to rely on it, especially if older
implementations such as JavaScript 1.2/1.3 of Netscape 4.x should be
considered. Certainly your SpiderMonkey build not having Unicode support
compiled in (for whatever reason) provides no valid argument at all in favor
of avoiding Unicode identifiers. Obviously it is compiled into the version
implemented in Gecko.
and stick to ASCII characters in identifiers.
A property *name* does not need to be an identifier:

var foo = {"bar[]": "baz"};
foo["bar[]"] = 42;

Hint: `this' can be the base object of a property access.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Oct 29 '08 #6
Stevo wrote:
PhpCool wrote:
>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.

The characters [ and ] aren't valid in a name. You can use a-z, A-Z and
0-9 and underscore. That's it.
....as I said, I used cond[] as a name and it worked perfectly for me.
Oct 29 '08 #7
On 2008-10-29 02:13, Thomas 'PointedEars' Lahn wrote:
>According to the standard, almost any Unicode letter (or
correspondin g escape sequence) can be used in an Identifier:

That's nonsense, at best misleading.
No, it's correct. Please re-read what I actually wrote. I said "almost
any Unicode *letter*", not character. There's a difference.
>UnicodeLette r
any character in the Unicode categories “Uppercase letter (Lu)”,
“Lowercase letter (Ll)”, “Titlecase letter (Lt)”,
“Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number
(Nl)”.

Note that "[" and "]" do _not_ occur and are _not_ contained in the
mentioned Unicode subsets;
I never said they were.
>So, all in all it's probably not a good idea to rely on it,

It *might not* be a good idea to rely on it, especially if older
implementations such as JavaScript 1.2/1.3 of Netscape 4.x should be
considered. Certainly your SpiderMonkey build not having Unicode
support compiled in (for whatever reason) provides no valid argument
at all in favor of avoiding Unicode identifiers. Obviously it is
compiled into the version implemented in Gecko.
Yeah, I had some trouble compiling it, and you're right, the quick test
with jsshell didn't prove much. I only tried it out of curiosity (and
because I was too lazy to start the Windows VM for IE and Safari).

[a little OT SpiderMonkey detour] The default compile went without a
hitch, but when I tried to use different configurations (like adding
support for the old File object), it always failed. The suggestions I
found in m.d.t.js-engine didn't work for me, but I found out that the
stand-alone SpiderMonkey interpreter probably wasn't what I was looking
for anyway. Somebody suggested JSDB, which embeds the SpiderMonkey
engine and comes with an assortment of useful host objects. I asked
about that here a few days ago, but haven't found the time to try it out
yet. [end detour :-)]
A property *name* does not need to be an identifier:

var foo = {"bar[]": "baz"}; foo["bar[]"] = 42;

Hint: `this' can be the base object of a property access.
Thanks, I'm aware of that, and I was specifically talking about
identifiers. But the OP will be interested in this snippet.
- Conrad
PS: While I'm already off-topic, could I ask you a personal favor? You
have a habit of starting your replies with "Nonsense." I personally find
it very rude to summarily dismiss another poster's opinion as nonsense.
It comes very close to an insult. I don't know if this is some kind of
language-barrier thing (unlikely because your English is practically
indistinguishab le from a native speaker; but it's possible). I like
talking to you, and I value your insightful comments. I've made my share
of mistakes, as have we all, and I'm always grateful for corrections,
but your "Nonsense" tags only serve to make me defensive and angry. I
wish you could find a different, more polite form of expressing your
disagreement - especially when you see that the person you're replying
to has actually tried to make a logical argument. Sure, I can "stand the
heat", as you've described it before. I just don't see any reason for
unprovoked fire and flames in a technical discussion. It's your choice,
of course, but you should be aware of how it will be received.
Oct 29 '08 #8
On Oct 28, 10:59*pm, Conrad Lender <crlen...@yahoo .comwrote:
On 2008-10-29 02:13, Thomas 'PointedEars' Lahn wrote:
[snip]
>
PS: While I'm already off-topic, could I ask you a personal favor? You
You should have done that by email.
have a habit of starting your replies with "Nonsense." I personally find
it very rude to summarily dismiss another poster's opinion as nonsense.
It comes very close to an insult. I don't know if this is some kind of
Personally, I don't condone such behavior, but more often than not, he
is calling a spade a spade.
Oct 29 '08 #9
Thomas 'PointedEars' Lahn wrote:
Conrad Lender wrote:
>On 2008-10-28 13:29, Stevo wrote:
>>The characters [ and ] aren't valid in a name. You can use a-z, A-Z and
0-9 and underscore. That's it.
[...]
If you're talking about ECMAScript identifiers, it's not correct either.
According to the standard, almost any Unicode letter (or corresponding
escape sequence) can be used in an Identifier:

That's nonsense, at best misleading.
Oops: *letter*. Sorry, so that's not nonsense; but it is misleading because
identifiers are not names.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8************ *******@news.de mon.co.uk>
Oct 29 '08 #10

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

Similar topics

13
3546
by: Adrian Parker | last post by:
I have a PHP generated page which displays X many records. Each record has a checkbox preceding it. The user checks several checkboxes, and hits a delete button. All the corresponding records will be deleted. But I'm running into difficulty... Right now the NAME property of each check box is the primary key of the corresponding...
6
4731
by: LRW | last post by:
I have no idea if this is more a PHP question or Javascript question, because my problem hinges equally on both. I have a PHP script that queries a database and creates a list of rows for each item, each with their own checkbox one can select to do stuff later. The PHP script this form posts to creates an array of all the selected...
8
4012
by: John Banta | last post by:
Hi, I have created a 12 month calendar where each day has a check box whereby the user can indicate if that day is available or not available for a certain event. The calendar is 'drawn' in a single form rather than 12 separate forms. If the checkbox contained in each day within each month has a unique name such as 1August2003,...
2
2423
by: Edward | last post by:
The following html / javascript code produces a simple form with check boxes. There is also a checkbox that 'checks all' form checkboxes hotmail style: <html> <head> <title></title> </head> <body> <form name="myform" action=test.php method=post>
2
3220
by: jimi_xyz | last post by:
Sorry if this isn't the correct group, i don't think there is a group for straight HTML. I am trying to create a type of search engine. There are two radio buttons at the top, in the middle there is a text box, with the search button next to it, and at the bottom there are four check boxes. When the form loads one of the two radio buttons are...
10
5188
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...
10
1838
by: tadisaus2 | last post by:
Hello, I want to have a user to check at least 2 check boxes and NO more than 2 boxes. I have different checkbox names because I stored each nam on different field. I tried this code but nothing happened. Here is my code: function clickCtr(chk){ var ctr = 0; var frm = chk.form; for (var i=1; i<=4; i++){
2
5408
by: dkultasev | last post by:
Hello, I have small script which generates some listboxes. Their names are listXX (list01, list02, list03....). How to check if there are checked or not ? If I have 1 listbox and have it's name I do $_POST. But what to do in that situation ? Sincerely, Dmitrij
1
5173
by: Anuj | 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...
0
7521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
1
7473
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...
0
7810
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...
0
6044
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3501
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...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
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
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
764
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...

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.