Thanks in advance....
Regards,
Satheesh
"Satheesh Babu B" <b.sathe...@gmail.com> wrote in message
news:1129716536.8...@o13g2000cwo.googlegroups.com...
how to retrive the value of checkbox that is checked in checkboxlist
using javascript..
Regards,
Satheesh
document.getElementById('CheckBoxList1_0').value;
but it is giving the result as on. how to accomplish this one???
regards,
Satheesh
1. (Not a good one) ids for checkboxes in checkboxlists are created like
this:
"nameOfAcheckboxlist_nextNumber"
so you can loop
for (i = 0; i < number; i++)
{
if (document.getElementByID("checkboxlistName_" + i ).checked)
{
//do something
}
}
or
2. (Better one) On server side create a javascript array that contains
checkbox'es .ClientID
And on a client side loop through this array.
for (i = 0; i < idsArray.length; i++)
{
if (document.getElementByID(idsArray[i]).checked)
{
//do something
}
}
hope this helps.
"Satheesh Babu B" <b.sathe...@gmail.com> wrote in message
news:1129716536.8...@o13g2000cwo.googlegroups.com...
"Satheesh Babu B" <b.sathe...@gmail.com> wrote in message
news:1129719458.3...@z14g2000cwz.googlegroups.com...
<table id="CheckBoxList1" border="0" style="Z-INDEX: 104; LEFT: 384px;
POSITION: absolute; TOP: 112px">
<tr>
<td><input id="CheckBoxList1_0" type="checkbox"
name="CheckBoxList1:0" /><label for="CheckBoxList1_0">one</label></td>
</tr><tr>
<td><input id="CheckBoxList1_1" type="checkbox"
name="CheckBoxList1:1" /><label for="CheckBoxList1_1">2</label></td>
</tr><tr>
<td><input id="CheckBoxList1_2" type="checkbox"
name="CheckBoxList1:2" /><label for="CheckBoxList1_2">3</label></td>
</tr><tr>
<td><input id="CheckBoxList1_3" type="checkbox"
name="CheckBoxList1:3" /><label for="CheckBoxList1_3">4</label></td>
</tr>
</table>
Regards,
Satheesh
"Satheesh Babu B" <b.sathe...@gmail.com> wrote in message
news:1129721420.7...@o13g2000cwo.googlegroups.com...
>i have used the coding..
>
> document.getElementById('CheckBoxList1_0').value;
>
> but it is giving the result as on. how to accomplish this one???
I'm not sure what your problem is. When a checkbox is checked, it has a
value of 'on' - when it's not, it doesn't...
<script>
if(document.getElementById('CheckBoxList1_0').value == 'on')
{
alert('Checked');
}
else
{
alert('Not checked');
}
</script>
"Sebastian Wojciechowski" <sebastian_usenet :this funny sign: icsharp.net>
wrote in message news:OzFMN7J1...@TK2MSFTNGP09.phx.gbl...
I think its clear now..
if (document.getElementById("CheckBoxList1_0").checked)
{
// 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" <patri...@optusnet.com.au> wrote in message
news:utZOVEK1...@TK2MSFTNGP14.phx.gbl...
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_facilities". I have a "Test" button
which calls the following code:
###
function Button1_onclick() {
var cblist = "cblist_facilities";
var chkList1= document.getElementById(cblist);
var arrayOfCheckBoxes= chkList1.getElementsByTagName("input");
var arrayOfCheckBoxLabels= chkList1.getElementsByTagName("label");
var listcount = arrayOfCheckBoxes.length;
var displ="";
alert(listcount + " items in list.");
for(var i=0;i<arrayOfCheckBoxes.length;i++) {
displ= "" + (i+1) + ": " + arrayOfCheckBoxes[i].checked + " - "
+ arrayOfCheckBoxLabels[i].innerText;
alert(displ);
alert(arrayOfCheckBoxes[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 ***
RBL code
-----------------------
<asp:RadioButtonList ID="rblLoanType" runat="server"
CssClass="wizardFormRadio"
Font-Bold="False" RepeatLayout="Flow" Width="210px" >
<asp:ListItem Value="Normal Konto">Normal Konto</asp:ListItem>
<asp:ListItem Value="Udskudt forste betaling">Udskudt første
betaling</asp:ListItem>
<asp:ListItem Value="Kampagnekonto">Kampagnekonto</asp:ListItem>
</asp:RadioButtonList>
-----------------------
JS code
-----------------------
function getAmount(nform) {
var a = document.getElementById('<%= rblLoanType.ClientID %>_0').checked;
var b = document.getElementById('<%= rblLoanType.ClientID %>_1').checked;
var c = document.getElementById('<%= rblLoanType.ClientID %>_2').checked;
if ( nform == 0 || a == true) {
...
-----------------------
hop it helps
--
Bruno Alexandre
København, Danmark
"a portuguese in Denmark"
"RD Law" <nos...@yahoo.com> escreveu na mensagem
news:%23ImD1sA...@TK2MSFTNGP04.phx.gbl...
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.DataBind(), 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(object sender, EventArgs e)
{
this.DataBind();
foreach (ListItem var in CheckBoxList1.Items)
{
// aggiungo anche l'onclick
var.Attributes.Add("onclick", "javascript:ShowValue('" +
var.Text + "');");
}
}
</script>
Javascript code:
function ShowValue(ctl)
{
alert(ctl);
}
Don't forget of treating var.Text (or var.Value) as a string.