For what code to work, the JavaScript? In php, the only way you'll be able to get all the checkboxes that have been checked is to put the square brackets behind the name. For it to work in JavaScript, you have to reference the element such as....

document.forms[0].elements['list[]'][i].checked

or something along those lines....my JS is a bit rusty.

Shaun Thornburgh wrote:
John,

Thanks for your reply, but for the code to work the checkbox has to be
called 'list'

Shaun Thornburgh BSc Hons.
Assertia Ltd
-----------------------------
Web : http://www.assertia.net
Email : [EMAIL PROTECTED]
Office : 0845 123 2992
Mobile : 07976 711363


-----Original Message-----
From: John Nichel [mailto:[EMAIL PROTECTED] Sent: 21 March 2003 20:04
To: shaun
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] php and javascript


Put square brackets after the name of your checkboxes.....

<input type=checkbox name=list[] value="1">Home<br>
<input type=checkbox name=list[] value="2">Office<br>
etc....

Then you will be able to access all the boxes checked on your post page in an array....

$_POST['list']

shaun wrote:

Hi,

I'm not sure if this is a PHP or a JavaScript question but I have

found the


following code to enable me to select all of the checkboxes on my

form.


<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
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"; }
}
//  End -->
</script>

<form name=mon_formulaire action="" method=post>
<table>
<b>Where do you connect to the Internet from?</b><br>
<input type=checkbox name=list value="1">Home<br>
<input type=checkbox name=list value="2">Office<br>
<input type=checkbox name=list value="3">Friends' home<br>
<input type=checkbox name=list value="4">Post office<br>
<input type=checkbox name=list value="5">Internet Café<br>
<br>
<input type=button value="Check all"
onClick="this.value=check(this.form.list)">
</form>

The problem is that in the example all of the boxes are called list

and i


need to name each checkbox on my form with a different user_id so that

i can


collect the data sent from the form, is there a way around this?

Thanks in advance for any advice offered.













-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to