473,721 Members | 3,971 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 11894
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
5000
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
1996
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
5575
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 below. Please note that I have no previous experience programming in javascript. function...
1
7127
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
2009
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
1965
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
1538
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
1595
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. I am pasting my code below Please let me know wht am i doing wrong.
1
9381
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
8852
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
8736
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9227
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...
1
9145
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8020
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4497
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...
0
4761
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2590
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2143
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.