473,796 Members | 2,559 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

Nov 19 '05
14 7973
i am Simply giving values 1,2,3,4 as text and value for the checkbox
item in the checkboxlist.if i check the checkbox with text "1".How
should i get that value using javascript..

I think its clear now..

Nov 19 '05 #11
there are no values set for the checkboxes, so the value is alway empty,
but your are interested in if the the user checked the checkbox. in
javascript its just:

if (document.getEl ementById("Chec kBoxList1_0").c hecked)
{
// do something with checked box
}
note: the value of a checkbox is the value set in tag, and has nothing to do
with whether checked or not. the value is what is posted back in the
name/value pair if the box is checked.

-- bruce (sqlwork.com)
"Patrick.O. Ige" <pa********@opt usnet.com.au> wrote in message
news:ut******** ******@TK2MSFTN GP14.phx.gbl...
Is it DataBinded or is it in any other controls?
Patrick

"Satheesh Babu B" <b.************ @gmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
The code generated is...

<table id="CheckBoxLis t1" border="0" style="Z-INDEX: 104; LEFT: 384px;
POSITION: absolute; TOP: 112px">
<tr>
<td><input id="CheckBoxLis t1_0" type="checkbox"
name="CheckBoxL ist1:0" /><label for="CheckBoxLi st1_0">one</label></td>
</tr><tr>
<td><input id="CheckBoxLis t1_1" type="checkbox"
name="CheckBoxL ist1:1" /><label for="CheckBoxLi st1_1">2</label></td>
</tr><tr>
<td><input id="CheckBoxLis t1_2" type="checkbox"
name="CheckBoxL ist1:2" /><label for="CheckBoxLi st1_2">3</label></td>
</tr><tr>
<td><input id="CheckBoxLis t1_3" type="checkbox"
name="CheckBoxL ist1:3" /><label for="CheckBoxLi st1_3">4</label></td>
</tr>
</table>

Regards,
Satheesh


Nov 19 '05 #12

Did you ever find a solution to this? I am having a similar issue
without much luck of a solution. Have spent a few hours to no avail.

This is what I have found: When creating a CheckBoxList, at runtime it
is rendered as an HTML table. I, like you, need to get the value of
items checked, but am only receiving "on" for the value of all items,
checked or not. Looking at my source code of the rendered page, there
are no "Value" tags for the check boxes. I can get the "Label" value,
but that is a descriptive item; I need the value that I set in the
"DataValueField " at design time.

My CheckBoxList is named "cblist_facilit ies". I have a "Test" button
which calls the following code:

###

function Button1_onclick () {
var cblist = "cblist_facilit ies";
var chkList1= document.getEle mentById(cblist );

var arrayOfCheckBox es= chkList1.getEle mentsByTagName( "input");
var arrayOfCheckBox Labels= chkList1.getEle mentsByTagName( "label");
var listcount = arrayOfCheckBox es.length;
var displ="";

alert(listcount + " items in list.");

for(var i=0;i<arrayOfCh eckBoxes.length ;i++) {
displ= "" + (i+1) + ": " + arrayOfCheckBox es[i].checked + " - "
+ arrayOfCheckBox Labels[i].innerText;
alert(displ);
alert(arrayOfCh eckBoxes[i].value);
}

}

###

When run, the first alert correctly displays the number of checkboxes.
The second alert ("displ") correctly displays whether the checkbox is
checked or not and the correct descriptive label. However, the third
alert (...value) displays "on" for all checkboxes, checked or not.

Thoughts?

*** Sent via Developersdex http://www.developersdex.com ***
Oct 4 '06 #13
this is what I'm using in a RabioButoonList (and it's Online and work
perfectly)

RBL code
-----------------------
<asp:RadioButto nList ID="rblLoanType " runat="server"
CssClass="wizar dFormRadio"

Font-Bold="False" RepeatLayout="F low" Width="210px" >

<asp:ListItem Value="Normal Konto">Normal Konto</asp:ListItem>

<asp:ListItem Value="Udskudt forste betaling">Udsku dt første
betaling</asp:ListItem>

<asp:ListItem Value="Kampagne konto">Kampagne konto</asp:ListItem>

</asp:RadioButton List>

-----------------------

JS code
-----------------------
function getAmount(nform ) {

var a = document.getEle mentById('<%= rblLoanType.Cli entID %>_0').checked ;

var b = document.getEle mentById('<%= rblLoanType.Cli entID %>_1').checked ;

var c = document.getEle mentById('<%= rblLoanType.Cli entID %>_2').checked ;

if ( nform == 0 || a == true) {

...

-----------------------

hop it helps
--

Bruno Alexandre
København, Danmark

"a portuguese in Denmark"
"RD Law" <no****@yahoo.c omescreveu na mensagem
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>
Did you ever find a solution to this? I am having a similar issue
without much luck of a solution. Have spent a few hours to no avail.

This is what I have found: When creating a CheckBoxList, at runtime it
is rendered as an HTML table. I, like you, need to get the value of
items checked, but am only receiving "on" for the value of all items,
checked or not. Looking at my source code of the rendered page, there
are no "Value" tags for the check boxes. I can get the "Label" value,
but that is a descriptive item; I need the value that I set in the
"DataValueField " at design time.

My CheckBoxList is named "cblist_facilit ies". I have a "Test" button
which calls the following code:

###

function Button1_onclick () {
var cblist = "cblist_facilit ies";
var chkList1= document.getEle mentById(cblist );

var arrayOfCheckBox es= chkList1.getEle mentsByTagName( "input");
var arrayOfCheckBox Labels= chkList1.getEle mentsByTagName( "label");
var listcount = arrayOfCheckBox es.length;
var displ="";

alert(listcount + " items in list.");

for(var i=0;i<arrayOfCh eckBoxes.length ;i++) {
displ= "" + (i+1) + ": " + arrayOfCheckBox es[i].checked + " - "
+ arrayOfCheckBox Labels[i].innerText;
alert(displ);
alert(arrayOfCh eckBoxes[i].value);
}

}

###

When run, the first alert correctly displays the number of checkboxes.
The second alert ("displ") correctly displays whether the checkbox is
checked or not and the correct descriptive label. However, the third
alert (...value) displays "on" for all checkboxes, checked or not.

Thoughts?

*** Sent via Developersdex http://www.developersdex.com ***

Oct 5 '06 #14
>i am Simply giving values 1,2,3,4 as text and value for the >checkbox
item in the checkboxlist
[cut]

Hello, all,
I also had to face such a thing and I solved it in a quite simple way.
When loading your page, after doing Page.DataBind() (or
CheckBoxList1.D ataBind(), it's the same), you should loop on your
checkbox items, and add an "onclick" attribute. This attribute should
call a function that contains, as an argument, the value (or text,
depending on what you have to do with it; for me it's necessary a text)
of your list item. Here it is my code:

On aspx page:
<script runat="server">

protected void Page_Load(objec t sender, EventArgs e)
{
this.DataBind() ;
foreach (ListItem var in CheckBoxList1.I tems)
{
// aggiungo anche l'onclick
var.Attributes. Add("onclick", "javascript:Sho wValue('" +
var.Text + "');");
}
}
</script>

Javascript code:
function ShowValue(ctl)
{
alert(ctl);
}

Don't forget of treating var.Text (or var.Value) as a string.

*** Sent via Developersdex http://www.developersdex.com ***
May 24 '07 #15

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

Similar topics

1
3253
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.
2
13710
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, Satheesh
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
6532
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
1840
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
6410
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>
7
2228
by: ThunderMusic | last post by:
Hi, I have a CheckBoxList and I want to add some javascript code to each CheckBox created by this CheckBoxList. I tried iterating through all items of the list, all the controls, do a FindControl, et al. with no good result. I would use the Control.Attribute.Add("OnClick", "some javascript code") Does someone know a solution? Thanks
2
5526
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
9673
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
9525
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
10452
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
10221
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
9050
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
6785
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();...
1
4115
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
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
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.