javascript - Toggle for multiple checkboxes – prototype js -


i'm trying implement toggle multiple checkboxes if switch 1 manually, checkbox no longer considered toggle.

var publishall = $("toggle");  publishall.observe('click', function(e){  	var state = null;  	if(this.checked) {  		state = "checked";  	}   	$$('.checkbox').invoke('writeattribute', 'checked', state);  });
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>  <input id="toggle" type="checkbox" name="toggle" value="true"> toggle checkbox<br /><br />        check these manually , won't work toggle anymore.<br />  <input class="checkbox" type="checkbox" name="checkbox[]" value="1"><br />  <input class="checkbox" type="checkbox" name="checkbox[]" value="2">

have done wrong?

instead of trying set attribute of checked "checked" need use javascript true or false use setvalue() method

so can simplify javascript this

$("toggle").observe('click', function(e){   $$('.checkbox').invoke('setvalue',this.checked); }); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -