Satheesh said:
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
.checked) return rSet.value;
}
}
function showAllChecked(f)
{
var el, els = f.elements;
var x = '';
var i = els.length;
while(i--){
el = els;
if (el.checked){
x += '\n' + el.type + ': ' + el.value;
}
}
return x;
}
</script>