473,657 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

send checkbox array in javascript function

realin
254 Contributor
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="modalDat a" id="multipleCom mSelect" style="padding: 50px;">

<center>Pleas e 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" >Decentralizati on</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="referC omm('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 5300
gits
5,390 Recognized Expert Moderator Expert
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 Contributor
thanks gits
i was able to do it :)
Apr 29 '08 #3
gits
5,390 Recognized Expert Moderator Expert
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
4688
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 the data (mysql select), I want that checkbox to be remembered. Basically I want the user to have multiple selections of checkboxes when paging through data (recordset), then they click a "continue" button, it
0
2124
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 construct a checkbox array in a survey form where one of the choices is "No Preference" which is checked by default. If the victim chooses other than "No Preference", I'd like to uncheck
4
6592
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 one checkbox (these are dynamically generated). Why does this fail? If I do an alert(field_to_check.length) with 1 element in the array like this I get 'Undefined'. Is this because this datatype is not an array if there is only 1 element here? ...
5
1922
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. people have the check at least one checkbox. i have made a form check to see of at least one checkbox is selected. this workts fine.
6
10403
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 group by using a two dimensional array. <form name=msgs>
4
6734
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 frame on this page that contains multiple checkboxes with the same name/id. This is a search form and users need the ability to select which categories they would like to search for. I have to put the categories in an inline frame to save real...
0
3105
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td colspan="2"><p>
13
3068
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 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...
0
8425
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8845
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8622
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2745
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
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.