[thelist] javascript error turning brain to mush (checkbox toggles)

m guckeyson markguy27 at ameritech.net
Thu Jan 30 18:17:01 CST 2003


H'lo folks...
I think something very similar to my problem was covered recently, but I'm
unable to find the thread now... and I can't just link you to the code,
seeing how my DSL provider has apparently cut off my server. Without
warning. Or explanation. So, I'm sorry for the possible repetitive question
and for what's about to follow as well...

Basically, I'm looking to be able to toggle all of a form's checkboxes on
and off with button onClick.

First the function:

function toggleAll( formObj ) {
	for ( var i = 0 ; i < formObj.length ; i++ ) {
		fieldObj = formObj.elements[i];
		if ( fieldObj.type == 'checkbox' ) {
			fieldObj.checked = ( fieldObj.checked ) ? false : true ;
		}
	}
}

Then there's a bunch of checkboxes eerily similar to these guys:

<form name="add_tracks" action="playlist.php" method="post">
	<input type="checkbox" id="track_68" name="add_tracks[]" value="68"
class="search_input_checkbox"></input>
	<input type="checkbox" id="track_72" name="add_tracks[]" value="68"
class="search_input_checkbox"></input>

...etc... and then the button o' despair:

	<input type="button" name="toggle_tracks" value="toggle tracks"
onclick=toggleAll( this.form ) class="search_input_submit"></input>
</form>

Could someone point out my glaringly obvious mistake? My brain thanks you... ;)

mark




More information about the thelist mailing list