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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkboxes - select all, automatic checks placed?

Status
Not open for further replies.

kentara

Programmer
Apr 13, 2005
38
US
I have ten checkboxes on my stage. As soon as a user puts a check in the tenth checkbox, I would like checks to automatically be put in checkboxes 1-9. Is this possible, and if so, how?
 
assuming they are all on the root and have instance names chk1-chk10 then

Code:
chk10.setChangeHandler("checkAll");
function checkAll() {
	if (chk10.getValue()) {
		for (i=1; i<10; i++) {
			_root["chk"+i].setValue(true);
		}
	} else {
		for (i=1; i<10; i++) {
			_root["chk"+i].setValue(false);
		}
	}
}
 
Thanks for responding, billwatson!

I adapted that code to my Flash movie (which now has 8 checkboxes and an "All boxes" checkbox), however it still doesn't seem to work - that is, I can't get it to return even the trace output, much less draw checkmarks in every checkbox when the "All boxes" checkbox (chk_AALL) is checked.

Is there anything I'm missing?

Code:
chk_AALL.setChangeHandler("checkAll");
function checkAll() {
	trace("in function");
    if (chk_AALL.value == true) {
        for (i=1; i<8; i++) {
            ["chk_A0"+i].setValue(true);
			trace(i + " true");
        }
    } else if (chk_AALL.value == false) {
        for (i=1; i<8; i++) {
            ["chk_A0"+i].setValue(false);
			trace(i + " false");
        }
    }
}
 
apart from chk_AALL.getValue() all looks ok

put up the fla for download and ill take a look at it or email it to me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top