473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Arrays as form elemtents

I'm passing numerous array elements called list[] when a form is submitted.
the brackets [ ] are necessary for PHP to see all the values as an array.
The problem is I can't seem to reference the form elements from javascripts
because of the brackets. For example,
form.list[].value is no good. Anyone know a way around this? Thanks.
Jul 20 '05 #1
12 2278
"szar" <no**@nowhere.net> writes:
I'm passing numerous array elements called list[] when a form is submitted.
the brackets [ ] are necessary for PHP to see all the values as an array.
The problem is I can't seem to reference the form elements from javascripts
because of the brackets. For example,
form.list[].value is no good. Anyone know a way around this? Thanks.


<URL:http://jibbering.com/faq/#FAQ4_25>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
"szar" <no**@nowhere.net> wrote in message
news:zl***************@newssvr24.news.prodigy.com. ..
I'm passing numerous array elements called list[] when a form is submitted. the brackets [ ] are necessary for PHP to see all the values as an array. The problem is I can't seem to reference the form elements from javascripts because of the brackets. For example,
form.list[].value is no good. Anyone know a way around this? Thanks.


Quick answer:-

<URL: http://jibbering.com/faq/#FAQ4_25 >

- and follow links from :-

<URL: http://jibbering.com/faq/#FAQ4_39 >

- to understand .

Richard.
Jul 20 '05 #3

"Richard Cornford" <ri*****@litotes.demon.co.uk> wrote in message
news:bj**********@sparta.btinternet.com...
"szar" <no**@nowhere.net> wrote in message
news:zl***************@newssvr24.news.prodigy.com. ..
I'm passing numerous array elements called list[] when a form is

submitted.
the brackets [ ] are necessary for PHP to see all the values as an

array.
The problem is I can't seem to reference the form elements from

javascripts
because of the brackets. For example,
form.list[].value is no good. Anyone know a way around this? Thanks.


Quick answer:-

<URL: http://jibbering.com/faq/#FAQ4_25 >

- and follow links from :-

<URL: http://jibbering.com/faq/#FAQ4_39 >

- to understand .

Richard.


Call me stupid but that didn't seem to work. Here's the script I'm using,
maybe it'll help:

<SCRIPT LANGUAGE="JavaScript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}
</script>

<form>
<input type=checkbox value="Check All"
onClick="this.value=check(this.form.list)">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
..
..
..
</form>

Basically, clicking the top checkbox checks (or unchecks) all the ones
below. This works how it is but I need the checkbox names to be list[]
instead of list. If anyone could edit the above code to give me a better
idea I'd be greatful!!!
Thanks!
Jul 20 '05 #4
this helpfull ?

<SCRIPT LANGUAGE="JavaScript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}

function test()
{
myname.list[0].checked = true;
}

function test2(checkboxnum)
{
this.checkboxnum = checkboxnum
myname.list[checkboxnum].checked = true;
}
</script>

<form name="myname">
<input type=checkbox value="Check All"
onClick="this.value=check(this.form.list)">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
</form>
<a href="javascript:test()">turn on the checkbox list 0</a>
<br>
or
<br>
<a href="javascript:test2('0')">turn on the checkbox list 0</a>

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:4q**********@hotpop.com...
"szar" <no**@nowhere.net> writes:
I'm passing numerous array elements called list[] when a form is submitted. the brackets [ ] are necessary for PHP to see all the values as an array. The problem is I can't seem to reference the form elements from javascripts because of the brackets. For example,
form.list[].value is no good. Anyone know a way around this? Thanks.


<URL:http://jibbering.com/faq/#FAQ4_25>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #5
added 3rd option
<SCRIPT LANGUAGE="JavaScript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}

function test()
{
myname.list[0].checked = true;
}

function test2(checkboxnum)
{
this.checkboxnum = checkboxnum
myname.list[checkboxnum].checked = true;
}

function test3(checkboxnum)
{
this.checkboxnum = checkboxnum
myname.elements[checkboxnum].checked = true;
}
</script>

<form name="myname">
<input type=checkbox value="Check All"
onClick="this.value=check(this.form.list)">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
..
..
..
</form>
<a href="javascript:test()">turn on the checkbox list 0</a>
<br>
or
<br>
<a href="javascript:test2('0')">turn on the checkbox list 0</a>
<br>
or
<br>
<a href="javascript:test3('0')">turn on the checkbox list 0</a>

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:4q**********@hotpop.com...
"szar" <no**@nowhere.net> writes:
I'm passing numerous array elements called list[] when a form is submitted. the brackets [ ] are necessary for PHP to see all the values as an array. The problem is I can't seem to reference the form elements from javascripts because of the brackets. For example,
form.list[].value is no good. Anyone know a way around this? Thanks.


<URL:http://jibbering.com/faq/#FAQ4_25>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #6
> var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";


It isn't a good idea to use the string "true" and "false" as boolean flags. The
language has boolean true and false, use those instead. Otherwise, you could
have a mixup. "false" is usually assumed to be true.

http://www.crockford.com/#javascript

Jul 20 '05 #7

"Douglas Crockford" <no****@laserlink.net> wrote in message
news:bj**********@sun-news.laserlink.net...
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
It isn't a good idea to use the string "true" and "false" as boolean

flags. The language has boolean true and false, use those instead. Otherwise, you could have a mixup. "false" is usually assumed to be true.

http://www.crockford.com/#javascript


Thanks Douglas, good point. This was just a script I downloaded and I
followed another good rule, if it ain't broke, don't fix it, so I just left
it.
Jul 20 '05 #8

"ziemon" <ne**@ziemon.nl> wrote in message
news:bj**********@news1.tilbu1.nb.home.nl...
added 3rd option
<SCRIPT LANGUAGE="JavaScript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}

function test()
{
myname.list[0].checked = true;
}

function test2(checkboxnum)
{
this.checkboxnum = checkboxnum
myname.list[checkboxnum].checked = true;
}

function test3(checkboxnum)
{
this.checkboxnum = checkboxnum
myname.elements[checkboxnum].checked = true;
}
</script>

<form name="myname">
<input type=checkbox value="Check All"
onClick="this.value=check(this.form.list)">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
.
.
.
</form>
<a href="javascript:test()">turn on the checkbox list 0</a>
<br>
or
<br>
<a href="javascript:test2('0')">turn on the checkbox list 0</a>
<br>
or
<br>
<a href="javascript:test3('0')">turn on the checkbox list 0</a>

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:4q**********@hotpop.com...
"szar" <no**@nowhere.net> writes:
I'm passing numerous array elements called list[] when a form is submitted. the brackets [ ] are necessary for PHP to see all the values as an array. The problem is I can't seem to reference the form elements from javascripts because of the brackets. For example,
form.list[].value is no good. Anyone know a way around this? Thanks.


<URL:http://jibbering.com/faq/#FAQ4_25>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'



I appreciate all the help but it still doesn't work. I think using elements
was on the right track but appearently I don't know enough about it to get
it to work. Here's what I want to happen:

<SCRIPT LANGUAGE="JavaScript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}
</script>
<form>
<input type=checkbox value="Check All"
onClick="this.value=check(this.form.list[])">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">
..
..
..
</form>

However, the passing of list[] to the check function done in the onClick of
the first checkbox gives an error. Help, pleeeeeeeeeeeeeeeeease!
Jul 20 '05 #9
"szar" <no**@nowhere.net> wrote
Call me stupid but that didn't seem to work. Here's the script I'm using,
maybe it'll help:

<SCRIPT LANGUAGE="JavaScript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}
</script>

<form>
<input type=checkbox value="Check All"
onClick="this.value=check(this.form.list)">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
.
.
.
</form>

Basically, clicking the top checkbox checks (or unchecks) all the ones
below. This works how it is but I need the checkbox names to be list[]
instead of list. If anyone could edit the above code to give me a better
idea I'd be greatful!!!
Thanks!

<input type=checkbox value="Check All"
onClick="this.value=check(this.form.elements['list[]'])">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">
Jul 20 '05 #10
szar wrote:
"ziemon" <ne**@ziemon.nl> wrote in message
news:bj**********@news1.tilbu1.nb.home.nl...
added 3rd option
<SCRIPT LANGUAGE="JavaScript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}

function test()
{
myname.list[0].checked = true;
}

function test2(checkboxnum)
{
this.checkboxnum = checkboxnum
myname.list[checkboxnum].checked = true;
}

function test3(checkboxnum)
{
this.checkboxnum = checkboxnum
myname.elements[checkboxnum].checked = true;
}
</script>

<form name="myname">
<input type=checkbox value="Check All"
onClick="this.value=check(this.form.list)">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
.
.
.
</form>
<a href="javascript:test()">turn on the checkbox list 0</a>
<br>
or
<br>
<a href="javascript:test2('0')">turn on the checkbox list 0</a>
<br>
or
<br>
<a href="javascript:test3('0')">turn on the checkbox list 0</a>

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:4q**********@hotpop.com...
"szar" <no**@nowhere.net> writes:

> I'm passing numerous array elements called list[] when a form is

submitted.
> the brackets [ ] are necessary for PHP to see all the values as an

array.
> The problem is I can't seem to reference the form elements from

javascripts
> because of the brackets. For example,
> form.list[].value is no good. Anyone know a way around this? Thanks.

<URL:http://jibbering.com/faq/#FAQ4_25>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'



I appreciate all the help but it still doesn't work. I think using elements
was on the right track but appearently I don't know enough about it to get
it to work. Here's what I want to happen:

<SCRIPT LANGUAGE="JavaScript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}
</script>
<form>
<input type=checkbox value="Check All"
onClick="this.value=check(this.form.list[])">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">
.
.
.
</form>

However, the passing of list[] to the check function done in the onClick of
the first checkbox gives an error. Help, pleeeeeeeeeeeeeeeeease!


You were told in the first response to your intial post:

<url: http://jibbering.com/faq/#FAQ4_25 />

4.25 My element is named myselect[] , how do I access it?

Form elements with any "illegal" characters can be accessed with
formref.elements["myselect[]"] - These characters are illegal in the standard
(x)HTML doctypes, so you should try to avoid them as browsers may perform
incorrectly though.

So your answer is:

Use check(this.form.elements['list[]']) instead of check(this.form.list[])

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #11

"Vjekoslav Begovic" <vj*******@inet.hr> wrote in message
news:bj**********@sunce.iskon.hr...
"szar" <no**@nowhere.net> wrote
Call me stupid but that didn't seem to work. Here's the script I'm using, maybe it'll help:

<SCRIPT LANGUAGE="JavaScript">
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}
</script>

<form>
<input type=checkbox value="Check All"
onClick="this.value=check(this.form.list)">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
<input type="checkbox" name="list" value="thisisdifferentforeach">
.
.
.
</form>

Basically, clicking the top checkbox checks (or unchecks) all the ones
below. This works how it is but I need the checkbox names to be list[]
instead of list. If anyone could edit the above code to give me a better
idea I'd be greatful!!!
Thanks!

<input type=checkbox value="Check All"
onClick="this.value=check(this.form.elements['list[]'])">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">


That did it! Thanks so much for your help VB!
Jul 20 '05 #12
In article <0s**********@newssvr24.news.prodigy.com>,
"szar" <no**@nowhere.net> wrote:

I appreciate all the help but it still doesn't work. I think using elements
was on the right track but appearently I don't know enough about it to get
it to work. Here's what I want to happen:
<form>
<input type=checkbox value="Check All"
onClick="this.value=check(this.form.list[])"> <input type="checkbox" name="list[]" value="thisisdifferentforeach">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">
<input type="checkbox" name="list[]" value="thisisdifferentforeach">


Change to

onClick="this.value=check(this.form['list[]'])">

so Javascript doesn't look for the array list.

But you're violating basic HTML doing this, so I
wouldn't trust this code across browsers. Names

...must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]),
hyphens ("-"), underscores ("_"), colons (":"),
and periods (".").

http://www.w3.org/TR/html4/types.html
Jul 20 '05 #13

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

Similar topics

0
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------------------------------------------- Parameters: $formField1: The name of the first array $formField2:...
10
by: Chamomile | last post by:
I have been happily using array members as id's in my html code (either hand coded or generated by server-side script-php ) for some time. eg < input type='text' id='arrayItem' >< input...
2
by: Mark Hannon | last post by:
I am trying to wrap my brain around storing form elements inside variables & arrays before I move on to a more complicated project. I created this simple example to experiment and as far as I can...
8
by: Greg | last post by:
In VB6 I made heavy use of control arrays I see they have been 'deprecated' in vb.Net, with a questionable explanation that they are no longer necessary which just addresses the event issue!...
38
by: ssg31415926 | last post by:
I need to compare two string arrays defined as string such that the two arrays are equal if the contents of the two are the same, where order doesn't matter and every element must be unique. ...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
1
by: assgar | last post by:
Hello I have changed the process code abit so it receives the data from the form and ensures the data in array format. This has eliminated my previous error. The problem I am experiencing...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.