473,774 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Geting Checkboxlist value in javascript


hai..
am having a checkboxlist..n ow how do i get the value of the checkbox
that is checked in checkboxlist using javascript?
Thanks in advance....
Regards,
Satheesh

Oct 19 '05 #1
2 13708
What does mean "checkboxli st"? HTML doesn't contain "checkboxli st"
element.

Please, make a part of your HTML code here.

Best, Ed.

Satheesh Babu B wrote:
hai..
am having a checkboxlist..n ow how do i get the value of the checkbox
that is checked in checkboxlist using javascript?
Thanks in advance....
Regards,
Satheesh


Oct 19 '05 #2
Satheesh Babu B wrote:
hai..
am having a checkboxlist..n ow how do i get the value of the checkbox
that is checked in checkboxlist using javascript?


If you mean a radio set, then you loop through the elements and find out
which one is checked. If you mean which checkbox is checked, it's much
the same - search through the checkboxes looking for the ones that have
been checked.

Just remember that when you reference form controls by name, you may get
a collection (radio buttons should always be a collection but it's not
guaranteed) or a single element

Here's some play code:

<form action="">
<div>
<input type="radio" name="rs1" value="zero" checked>zero
<input type="radio" name="rs1" value="one">one
<input type="radio" name="rs1" value="two">two
<br>
<input type="checkbox" name="cb1" value="cb 1">cb 1
<input type="checkbox" name="cb2" value="cb 2">cb 2
<input type="checkbox" name="cb3" value="cb 3">cb 3
<br>
<input type="button" value="Show checked radio value" onclick="
alert(showRadio Checked(this.fo rm.rs1));
"><br>
<input type="button" value="Show all checked values" onclick="
alert(showAllCh ecked(this.form ));
"><br>
<input type="reset">
</div>
</form>

<script type="text/javascript">

function showRadioChecke d(rSet)
{
var i = rSet.length;
while(i--){
if (rSet[i].checked) return rSet[i].value;
}
}

function showAllChecked( f)
{
var el, els = f.elements;
var x = '';
var i = els.length;
while(i--){
el = els[i];
if (el.checked){
x += '\n' + el.type + ': ' + el.value;
}
}
return x;
}
</script>

--
Rob
Oct 19 '05 #3

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

Similar topics

1
3251
by: Itai | last post by:
I am attempting to create an ASP.NET Custom Validator javascript for a checkboxlist control. My goal is to limit the total number of selections to be 1 - 5 at most. My problem is that I get a null reference when I attempt to retrieve an object for an individual list item, which of course results in an "object required" error message. Anyone know what to do? tnx in advance -Itai.
0
7949
by: Bryce Budd | last post by:
Hello All, I've been a taker of information from newsgroups for a long time and thought I'd finally make a contribution back to the community whose supported me when I've needed it. After all before commercialization took over that was the beauty of the Internet! I've create a checkboxlist validator control...something MS should have done originally in my opinion, but nonetheless here it is. It's a C# control, sort of IE specific. ...
3
5456
by: Robin Day | last post by:
I run some code on the changed event of checkbox lists. Its quite simple, nothing more than showing / hiding some other parts of the page. Using Autopostback and Server side code works fine, but is far too slow, especially if the users are on modems. I need to quite simply, add some java code to the onclick event of the input tags of a checkboxlist. However... Attributes.Add adds the onclick attribute and code to the outlying table that...
4
6530
by: Shaul Feldman | last post by:
Hello, I have something really awkward at work - fighting with CheckBoxList... How can I define CSS for ListItem in CheckBoxList programmatically. I add CheckBoxList's Items on the fly, something like dim li as ListItem li = new ListItem("title","value"); '' how to define here the CSS for List Item, not CheckBoxList?!?!?! myCheckBoxList.Items(x).add(li);
1
1835
by: Ryan Scully | last post by:
Hello I have problem with determining exactly what CheckBoxList element is selected using JavaScript code. When I databind to the checkboxlist it renders it on the page and instead of giving each checkbox a value, it gives it a name and does a <label> tag for the Text of the item, and has nothing about the value anywhere in the rendered code for the checkboxlist. So when I enumerate through the controls on the page in javascript, I can never...
3
6409
by: Roy | last post by:
The title is self-explanatory, but I'll show you all what I've done thus far. Here's the aspx side of things(trimmed, of course): <form name="form1" id="Form1" method="post" runat="server"> <table width="100%"> <tr> <td> <asp:CheckBoxList Runat="server" id="CheckBoxList1"> <asp:ListItem Value="a">Checked a</asp:ListItem>
14
7970
by: Satheesh Babu B | last post by:
hai.. am having a checkboxlist..now how do i get the value of the checkbox that is checked in checkboxlist using javascript? Thanks in advance.... Regards,
2
5524
by: Stimp | last post by:
I have a checkboxlist (chkMyList) which is created from a (name, value) pair from a database table. I have a read-only textbox which will be used to hold a total of all the numerical values of each checkbox that is checked, and this value will change dynamically via javascript when a box is ticked or unticked. e.g. <script language="javascript"> function GetCost() {
0
9621
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
9454
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
10267
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...
1
10040
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
9914
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...
0
5355
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
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
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.