Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CheckBoxes Help!!!

Status
Not open for further replies.

Vem786

Technical User
Dec 2, 2003
52
US
Hi:
I'm trying to use the code below to Check All checkboxes, If they aren't checked and Uncheck All If they are Checked. But somehow I dont get to see the Action!!!!

Can Anyone please point out whats wrong?

-------------------------------------
<HTML
<HEAD>
<TITLE> SELECT/UNSELECT CHECKBOXES</TITLE>
<script language=&quot;javascript&quot;>
function selectDeselect() {
var len = document.form1.elements.length;
//alert(len);=7

var boxes_checked = anyChecked();//If any of the boxes is CHECKEd it'll be TRUE
// If any of the boxes is NOT CHECKEd it'll be FALSE
alert(boxes_checked);

if(boxes_checked==false)
setChecks(true);
else
setChecks( false);

function setChecks( setting ) {

for( var i=0; i < len; i++ ) {

document.form1.myData[ i ].checked = setting;
}
}


function anyChecked() {
//alert(&quot;In func anychecked!!&quot;);

for( var i=0; i < len; i++ ) {
alert(&quot;In anyChecked func's for loop!!!&quot;);

if( document.form1.myData[ i ].checked == true ) {
//alert(&quot;In Anychecked IF&quot;);
return true;
}
}

return false;
}
}
</script>
</HEAD>
<BODY>
<form name=&quot;form1&quot;>
<input type=&quot;checkbox&quot; name=&quot;myData1&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData2&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData3&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData4&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData5&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData6&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData7&quot; />
</form>
<a href='#' onClick=&quot;selectDeselect();&quot;>Select/Deselect</a>
</body>
</html>
 
document.form1.myData[ i ].checked

should be

document.form1[&quot;myData&quot;+i].checked

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life--};
 
Sorry!!! Even after that change I don't get to see the action at all!!!

The Page Status Bar says &quot;Error on Page&quot;!!!

 
Adam is correct...note that it needs to be changed in two places.

also, in your loops you're starting at i == 0 but your checkboxes begin at 1 so I added one more checkbox:

<HTML
<HEAD>
<TITLE> SELECT/UNSELECT CHECKBOXES</TITLE>
<script language=&quot;javascript&quot;>
function selectDeselect() {
var len = document.form1.elements.length;

//If any of the boxes is CHECKEd it'll be TRUE
// If any of the boxes is NOT CHECKEd it'll be FALSE
var boxes_checked = anyChecked();

alert(boxes_checked);

if(boxes_checked==false)
setChecks(true);
else
setChecks( false);

function setChecks( setting ) {
for( var i=0; i < len; i++ ) {
document.form1.elements[&quot;myData&quot; + i ].checked = setting;
}
}


function anyChecked() {
for( var i=0; i < len; i++ ) {
if( document.form1[&quot;myData&quot; + i ].checked == true ) {
return true;
}
}

return false;
}
}
</script>
</HEAD>
<BODY>
<form name=&quot;form1&quot;>
<input type=&quot;checkbox&quot; name=&quot;myData0&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData1&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData2&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData3&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData4&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData5&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData6&quot; />
<input type=&quot;checkbox&quot; name=&quot;myData7&quot; />
</form>
<a href='#' onClick=&quot;selectDeselect();&quot;>Select/Deselect</a>
</body>
</html>

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
This is Incredible!!!

I'm just thankful to all of you.

 
good catch, jeff

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life--};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top