...

View Full Version : to check the consecutive checkbox



vamshi
06-29-2012, 07:13 AM
Hi ,




plz do help me for checking the consecutive checkboxes in a group of checkbox using if loop.



Regerds,
vamshi

Philip M
06-29-2012, 07:34 AM
plz do help me for checking the consecutive checkboxes in a group of checkbox using if loop.


I don't really understand your question - please be more specific.

This example may or may not be what you are wanting.



<form name = "myform">
RED <input type = "checkbox" name = "box" value = "red">
BLUE <input type = "checkbox" name = "box" value = "blue">
GREEN <input type = "checkbox" name = "box" value = "green">
YELLOW <input type = "checkbox" name = "box" balue = "yellow">
<br><br>
<input type = "button" value = "Boxes Checked?" onclick = "CheckBoxes()"
</form>

<script type = "text/javascript">

function CheckBoxes(){
var bool = false;
var count = 0;
for (var i=0;i<document.myform.box.length;i++) {
if (document.myform.box[i].checked) {
bool = true;
count++;
}
}
alert((bool)?"You've checked at least one box.":"You haven't checked any boxes!");
alert ("You have checked " + count + " boxes")
}
</script>

Another example:-


<form name = "myform">
<input name = "myname" type = "checkbox" value = "Red"> RED <br>
<input name = "myname" type = "checkbox" value = "Blue"> BLUE <br>
<input name = "myname" type = "checkbox" value = "Green"> GREEN <br>
<input name = "myname" type = "checkbox" value = "Yellow"> YELLOW<br><br>
<input type = "button" value = "Get Color Choices" onclick="cboxlist()"><br>
</form>

<script type = "text/javascript">

function cboxlist(){
var choice = "Your colour choice is: ";
var x = new Array();
var colors = document.myform.myname;
for ( i = 0; i < colors.length; i++ ) {
if ( colors[i].checked ) {
x.push(colors[i].value);
}
}
alert (choice + (x.length == 0 ? 'NONE' : x.join(' | ')));
}

</script>

Or do you want a code to check/uncheck all the checkboxes in a group when a button is clicked???


<script type = "text/javascript">
var checked = false;
function checkedAll () {
checked == true? checked = false:checked = true;
var els = document.getElementById("mydiv").getElementsByTagName("input");
var len = els.length;
for (var i = 0; i < len; i++) {
els[i].checked = checked;
}
}
</script>
</head>

<body>
<form id="myform">
<div id = "mydiv">
<input type="checkbox" name="chk1">
<input type="checkbox" name="chk2">
<input type="checkbox" name="chk3">
</div>
<br>
Check/Uncheck All: <input type="checkbox" name="checkall" onclick="checkedAll();">
</form>

Seen in the classified ads: Nice parachute - never opened - used once.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum