473,405 Members | 2,379 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,405 software developers and data experts.

Checkbox Array

3
Hi, I'm having a problem simply putting the values of selected checkboxes into an array using javascript.

The list of checkboxes is dynamically created so I need to count number of checkboxes in order to cycle through them. Also the value of these checkboxes is not 1,2,3,4,5. They are non-sequential id numbers.

[PHP] function update(chkbox_name)
{
var ids = new Array();
var count = 0;
for(var i=0; i < chkbox_name.length; i++)
{
if (chkbox_name[i].checked)
{
ids[count] = chkbox_name[i].value;
count = count++;
}
}
}

[/PHP]

The function is called here:
[PHP]onchange='update(this.form.group_chk);'[/PHP]

And this is the checkbox part of the form that is within a while loop (cycles through all selected group_ids which are not in numerical order):
[PHP]<input name="group_chk[]" type="checkbox" value="<?echo $group_id;?>" />[/PHP]

Can anyone give me a hand? thanks
May 16 '06 #1
3 8537
Banfa
9,065 Expert Mod 8TB
I suspect this is not correct

[php]
<input name="group_chk[]" type="checkbox" value="<?echo $group_id;?>" />
[/php]

I'd try

[php]
<input name="group_chk" type="checkbox" value="<?echo $group_id;?>" />
[/php]
May 16 '06 #2
aparth
3
thanks mate it worked!

i remember reading a tutorial that said without the [] checkboxes won't work....so many mixed messages on the web

cheers
May 17 '06 #3
acoder
16,027 Expert Mod 8TB
Checkbox arrays are usually required for a server-side language, e.g. PHP. This can also be used with JavaScript by using the form elements array or document.getElementsByName(), e.g.
Expand|Select|Wrap|Line Numbers
  1. onchange='update(this.form.elements["group_chk[]"]);'
Jun 22 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
4
by: Piotr | last post by:
how can I read (in alert for example) array index number of checked checkbox? I have: <input type="checkbox" id="id_number" name="check" value="1" onclick="show()"/> <input type="checkbox"...
6
by: Fred Flintstone | last post by:
I have an app that requires the use of a 2 dimensional array of checkboxes. I can't seem to assign any values to them. I tried this: Dim BonusChecks(0, 0) As CheckBox ...and then later when...
6
by: Chuck Anderson | last post by:
My knowledge of JavaScript is limited. I learn from example and then adapt those examples to suit my needs. I have stumped myself on this one. I have a form with checkboxes that I want to...
29
by: Amer Neely | last post by:
I've got a dynamically built form with checkboxes for each element ( a list of file names in a directory). I need to grab only those checkboxes that are checked, so I can then delete those files. ...
3
by: JackM | last post by:
Okay, I'm starting to get a little ticked off because I've worked for hours on this and I can't seem to find the cause. I'm using PHP 5.1.6. I'm trying to get the values of some form checkboxes...
1
by: newbie | last post by:
Hello All, I'm trying to figure out this array problem I have. I don't know if I'm doing this correctly. Anyone want to take a look. --------------------- Current Situation....
2
by: newbie | last post by:
Hello All, I'm trying to figure out this array problem I have. I don't know if I'm doing this correctly. Anyone want to take a look. --------------------- Current Situation....
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
0
by: msg4james | last post by:
G'day folks, I have an intriguing question, one which most programmers have been talking around, and the solutions I have seen posted often inadequate: <INPUT TYPE=CHECKBOX NAME="Profession" ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...
0
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,...
0
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...

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.