473,568 Members | 2,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting the Values of CheckBox(es) Selected

Hey All,
Can someone suggest me a way to get the values of CheckBox(es) selected
in a CheckBoxList control using JAVASCRIPT.
I am pasting my current code gere but its not working need some
suggestions pls.

function CheckBoxList(cn trlName)
{
var cntrlValue = listValuesCheck Box(cntrlName);
return cntrlValue ;
}
function listValuesCheck Box(objectName)
{
var list = "";
for (var i=0; i<objectName.le ngth;i++){
if (objectName.Opt ions[i].selected = true){
list += objectName.Opti ons[i].value+ '~';
}
}
return list;
}

Jul 23 '06 #1
6 11881
ri************* ***@gmail.com wrote:
if (objectName.Opt ions[i].selected = true){
This is an assignment, and therefore, will always evaluate to TRUE.

Use one of the following forms instead:

if (objectName.Opt ions[i].selected == true){

if (objectName.Opt ions[i].selected){
JW
Jul 23 '06 #2

ri************* ***@gmail.com wrote:
Hey All,
Can someone suggest me a way to get the values of CheckBox(es) selected
in a CheckBoxList control using JAVASCRIPT.
I am pasting my current code gere but its not working need some
suggestions pls.

function CheckBoxList(cn trlName)
{
var cntrlValue = listValuesCheck Box(cntrlName);
return cntrlValue ;
}
function listValuesCheck Box(objectName)
{
var list = "";
for (var i=0; i<objectName.le ngth;i++){
if (objectName.Opt ions[i].selected = true){
Careful with case, a select element has an options collection, not an
Options collection.

list += objectName.Opti ons[i].value+ '~';
}
}
return list;
Presuming that objectName is a reference to a select element, there is
no need to loop through all the options. The select element's
selectedIndex property will tell you which one is selected. Replace
the entre function with:

return '~' + objectName.opti ons[objectName.sele ctedIndex].value;
Modern browsers will be happy with:

return '~' + objectName.valu e;

}
--
Rob

Jul 23 '06 #3

Check at http://www.javascriptkit.com/javatut...diocheck.shtml on how to get the .checked
checkboxes :) .

Danny
Jul 23 '06 #4
Hey Rob,
When I replaced it with the line you told me JavaScript thows the Error
Below:-

Microsoft JScript runtime error: 'options' is null or not an object

Please Advise.

Thanks
RobG wrote:
ri************* ***@gmail.com wrote:
Hey All,
Can someone suggest me a way to get the values of CheckBox(es) selected
in a CheckBoxList control using JAVASCRIPT.
I am pasting my current code gere but its not working need some
suggestions pls.

function CheckBoxList(cn trlName)
{
var cntrlValue = listValuesCheck Box(cntrlName);
return cntrlValue ;
}
function listValuesCheck Box(objectName)
{
var list = "";
for (var i=0; i<objectName.le ngth;i++){
if (objectName.Opt ions[i].selected = true){

Careful with case, a select element has an options collection, not an
Options collection.

list += objectName.Opti ons[i].value+ '~';
}
}
return list;

Presuming that objectName is a reference to a select element, there is
no need to loop through all the options. The select element's
selectedIndex property will tell you which one is selected. Replace
the entre function with:

return '~' + objectName.opti ons[objectName.sele ctedIndex].value;
Modern browsers will be happy with:

return '~' + objectName.valu e;

}

--
Rob
Jul 23 '06 #5
ri************* ***@gmail.com wrote in news:1153687584 .732898.55360
@i42g2000cwa.go oglegroups.com:
Can someone suggest me a way to get the values of CheckBox(es) selected
in a CheckBoxList control using JAVASCRIPT.
Hi,

Note thad an option in a select control has the * selected * property.

Checkboxes and radio buttons have the * checked * property.
Jul 23 '06 #6

ri************* ***@gmail.com wrote:
Hey Rob,
Please don't top post, reply below trimmed quotes.
When I replaced it with the line you told me JavaScript thows the Error
Below:-

Microsoft JScript runtime error: 'options' is null or not an object
Probably because I expected you to be using a select element rather
than a set of checkboxes. Your original post was somewhat confusing,
here is an example of getting the selected checkboxes from a set:

<script type="text/javascript">

function listValuesCheck Box(checkBoxRef )
{
var list = [];
for (var i=0, len=checkBoxRef .length; i<len; i++){
if (checkBoxRef[i].checked){
list.push(check BoxRef[i].value);
}
}
alert(list.join ('\n'));
}

</script>

<form action="">
<label for="cb01"><inp ut type="checkbox" id="cb01"
name="cbSet1" value="cb 01">cb 01</label><br>
<label for="cb02"><inp ut type="checkbox" id="cb02"
name="cbSet1" value="cb 02">cb 02</label><br>
<label for="cb03"><inp ut type="checkbox" id="cb03"
name="cbSet1" value="cb 03">cb 03</label><br>
<input type="button" value="Show checked"
onclick="listVa luesCheckBox(th is.form.cbSet1) ;">
<input type="reset">
</form>
If you are trying to create a delimited list, a joined array is simpler
(and much faster in IE) than concatenating strings using the "+="
compound operator.
--
Rob

Jul 23 '06 #7

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

Similar topics

2
4995
by: Tripharn Teki | last post by:
Hi, I have the following code in the HTML <select size="1" name="newtitle"> <% // Need to fill select with available campuses while (titleit.hasNext()) { temp = (String)titleit.next(); // Check if it is the selected campus already
0
1987
by: Kumar | last post by:
Hi , I am using the article code shown in below url: http://www.codeproject.com/aspnet/xmlxsltransformer.asp?df=100&forumid=118504&select=1170328 This article is very cool feature. I am trying to implement this into my application.
0
5559
by: sam | last post by:
I have 2 radio buttons on my form which are hidden. I need to have these radio buttons visible once a checkbox is selected. The radio buttons are hidden on loading of the form but I cannot make them visible once the check box is checked. The error I get is 'document.radiology.rcontmedia.style' is null or not an object. The code I am using is...
1
7121
by: Mike P | last post by:
How do I get the values selected from a multiselect listbox? Cheers, Mike *** Sent via Developersdex http://www.developersdex.com ***
1
2001
by: Joel Reinford | last post by:
I am loading a checkbox list on a web form at runtime along with several other controls. I am unable to get to the checkbox list on postback, I always get an invalid cast exception. I have no trouble getting the other controls including a dropdown list. Any suggestions on what I could do would be appreciated. Joel Reinford
5
1960
by: Hassan Bassam | last post by:
I am having a problem. How can I get the selected text from a text editor. I am using ASP.NET and VB as language. Thanx
2
1533
by: Alex Smith | last post by:
Hi Friends, How can I check a checkbox selected more than one times in DataGrid ? My First Priority is check with Client Side(Java Script), if it is not easy than check server side (C#). Thanks Alex.
2
1588
by: rishabhshrivastava | last post by:
Hi All, I am using CallBack feature in ASP.NET 2.0 and I am running into a problem with checkboxlist control. I have to find out which checkboxes are checked and get their values at client-side(using JavaScript) but always I get a value "undefined"....this code works for all other controls except checkboxlist and radiobuttonlist controls....
1
9379
by: Mitesh | last post by:
Hi, I have the following HTML code right now. Code: ------------------------------------------------------------------------------------------------------------------------- <td width="20%"><SELECT NAME="cfg_input_global_report_types" MULTIPLE > <OPTION VALUE="BU" >Option1 <OPTION VALUE="BP" >Option2
0
7693
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...
0
7916
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. ...
0
8117
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...
1
7660
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6275
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5498
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...
1
2101
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
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.