By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,481 Members | 1,713 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,481 IT Pros & Developers. It's quick & easy.

Geting Checkboxlist value in javascript

P: n/a

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

Oct 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
What does mean "checkboxlist"? HTML doesn't contain "checkboxlist"
element.

Please, make a part of your HTML code here.

Best, Ed.

Satheesh Babu B wrote:
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


Oct 19 '05 #2

P: n/a
Satheesh Babu B wrote:
hai..
am having a checkboxlist..now 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(showRadioChecked(this.form.rs1));
"><br>
<input type="button" value="Show all checked values" onclick="
alert(showAllChecked(this.form));
"><br>
<input type="reset">
</div>
</form>

<script type="text/javascript">

function showRadioChecked(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 discussion thread is closed

Replies have been disabled for this discussion.