473,387 Members | 1,556 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.

send checkbox array in javascript function

realin
254 100+
Hiya all,

i am in deep trouble, i thought it was an easy task, but now its getting on my nerves.
Well i have a div on a form, which contains a number of checkboxes, as

[HTML]<div class="modalData" id="multipleCommSelect" style="padding: 50px;">

<center>Please select the communities from the list below:<br></center>

<label><input name="CommID[]" value="3" type="checkbox">AIDS</label><br>
<label><input name="CommID[]" value="4" type="checkbox">Decentralization</label><br>
<label><input name="CommID[]" value="5" type="checkbox">Disaster Management</label><br>
<label><input name="CommID[]" value="6" type="checkbox">Food and Nutrition Security</label><br>
<label><input name="CommID[]" value="7" type="checkbox">Education</label><br>
<label><input name="CommID[]" value="8" type="checkbox">Gender</label><br>

<label><input name="CommID[]" value="9" type="checkbox">ICT for Development</label><br>
<label><input name="CommID[]" value="10" type="checkbox">Maternal and Child Health</label><br>
<label><input name="CommID[]" value="11" type="checkbox">Microfinance</label><br>
<label><input name="CommID[]" value="12" type="checkbox">Water</label><br>
<label><input name="CommID[]" value="13" type="checkbox">Work and Employment</label><br>
<input value="Refer to selected communities" onclick="referComm('CommID');" type="button">

</div>[/HTML]

i want to send this array of checkboxes to a javascript function. But i am unable to do it. Please can anyone help me. There on i want to run some ajax function to store this info in DB, but i am unable to pass this checkbox array ..

pleaseee help me
regards
Realin !
Apr 29 '08 #1
3 5284
gits
5,390 Expert Mod 4TB
hi ...

you have to loop through the nodes with the name 'CommID[]' and build a javascript array from it ... like in the following example:

Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * returns an array with the values of the checked checkboxes with name
  3.  * @param name name of the checkboxes
  4.  * @return new_arr array with checked-values
  5.  */
  6. function get_array_for_checkboxes_with_name(name) {
  7.     var new_arr = [];
  8.     var nodes = document.getElementsByName(name);
  9.  
  10.     for (var i = 0, n; n = nodes[i]; i++) {
  11.         if (n.checked == true) {
  12.             new_arr.push(n.value);
  13.         }
  14.     }
  15.  
  16.     return new_arr;
  17. }
kind regards
Apr 29 '08 #2
realin
254 100+
thanks gits
i was able to do it :)
Apr 29 '08 #3
gits
5,390 Expert Mod 4TB
glad to hear that ... ;) post back to the forum anytime you have more questions ...

kind regards
Apr 29 '08 #4

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

Similar topics

1
by: RelaxoRy | last post by:
Reposted (not sure if got sent) I have results being displayed each with its own checkbox name "selected" and value "id". When someone checks a checkbox, and then continues to page through...
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: Michael Champagne | last post by:
We have an application to where you can select/deselect all checkboxes in a checkbox array by clicking a 'master' checkbox at the top of the screen. This seems to work fine unless there is only...
5
by: nescio | last post by:
hello, i am making a form using php/html/javascript a part of the form is (email address) comming from a database. the amount of addresses is always different. every address has a checkbox....
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...
4
by: Matt | last post by:
I am no JavaScript guru so please bear with me and be as detailed as possible with your response. I thank you in advance. I have an ASP page that contains form elements. I also have an inline...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
13
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.