Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Checkboxlist Client Side

0 views
Skip to first unread message

Bg

unread,
Apr 10, 2003, 5:11:10 PM4/10/03
to
I have several checkboxlist web controls on my page. I need to do some
actions on the client based on what the selected values are in the
checkboxlists. How can I loop through a checkboxlist and get the selected
values for a given checkboxlist on the client in javascript?


paul crowder

unread,
Apr 11, 2003, 11:17:22 AM4/11/03
to
View the source of the web page that gets generated. Do the checkboxes have
the same value for the name attribute? If so you can just use something
like this:

var chkBoxList = document.forms(0).items("nameofcheckboxlist");

for(i = 0; i < chkBoxList.length; i++)
{
if(chkBoxList[i].checked)
{
doWhatever();
}
}

Paul

"Bg" <noe...@here.com> wrote in message
news:uh282W6$CHA....@TK2MSFTNGP11.phx.gbl...

Bg

unread,
Apr 11, 2003, 5:32:00 PM4/11/03
to
How can I get the selected values in the checkboxlist? It looks like the
checkboxlist web control does not render any values in the html.

This is what you see if you view source from the browser (there are no
values anywhere even though I set them on the server side in the designer):

<table id="CheckBoxList1" onclick="GetCheckedValues();" border="0"
style="height:92px;width:211px;Z-INDEX: 112; LEFT: 19px; POSITION: absolute;
TOP: 14px">
<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">Two</label></td>
</tr><tr>
<td><input id="CheckBoxList1_2" type="checkbox" name="CheckBoxList1:2"
/><label for="CheckBoxList1_2">Other</label></td>
</tr>
</table>


The Myna Bird

unread,
May 6, 2003, 11:28:14 AM5/6/03
to
I think that maybe this can help:

Te following example is something i've used to doWathever with the
value of a checkBox in a CheckBoxList in client side.

---------------------------------------------------------------------------
C# in server side:
( lstVarios is a CheckBoxList )
( btnHacer is a HTML Button )
---------------------------------------------------------------------------
string script = "";
script = "<script language='JAVASCRIPT'> \n";
script = script + "function buscarEnLista ( id ) { \n";
for (int i=0 ; i < lstVarios.Items.Count ; i++)
{
script = script + "\t if (id == 'lstVarios_" + i + "') return
'" + lstVarios.Items[i].Value + "'; \n";
}
script = script + "\t return 'ERR';\n";
script = script + "} \n";
script = script + "</script>\n";
Page.RegisterClientScriptBlock("_checkKey_", script);
btnHacer.Attributes.Add("onclick", "revisarBotones();");
---------------------------------------------------------------------------
---------------------------------------------------------------------------
JavaScript in client side:
( doWathever is a function that does wathever ;) )
---------------------------------------------------------------------------
function revisarBotones()
{
var hayObj = true;
var pp = new Object();
var i = 0;
while( hayObj == true )
{
pp = document.getElementById('lstVarios_' + i);
if (pp == null)
{
hayObj = false;
}
else
{
valor = buscarEnLista(pp.id);
doWathever( valor );
}
i++;
}

}
---------------------------------------------------------------------------


"Bg" <noe...@here.com> wrote in message news:<#aR3KHHA...@TK2MSFTNGP11.phx.gbl>...

0 new messages