javascript - display alert on each selected check box from a group of checkboxes -



javascript - display alert on each selected check box from a group of checkboxes -

i have 3 checkboxes , want them actions i.e display alert box when checked , when 1 check box checked, others should unchecked.

i've been able sec part work 1 checkbox can checked @ time can't seem create first part of displaying alert box work.

js ensures 1 box checked @ time:

function qtybox(e) { var c = document.getelementsbyclassname("qty"); (var = 0; < c.length; i++) { c[i].checked = false; } e.checked = true; }

html:

<input class="qty" type="checkbox" id="pails" onchange="qtybox(this)"/>pails <input class="qty" type="checkbox" id="liters" onchange="qtybox(this)"/>liters <input class="qty" type="checkbox" id="gallons" onchange="qtybox(this)"/>gallons

now that's left when pails checked,i want alert box display pails. when liters checked, alert box display liters , when gallons checked, alert box display gallons.

you need reference input. add:

var currid = e.id; if(currid === "pails") alert("pails"); else if(currid === "liters") alert("liters"); else if(currid === "gallons") alert("gallons");

so become:

function qtybox(e) { var c = document.getelementsbyclassname("qty"); (var = 0; < c.length; i++) { c[i].checked = false; } e.checked = true; var currid = e.id; if(currid === "pails") alert("pails"); else if(currid === "liters") alert("liters"); else if(currid === "gallons") alert("gallons"); }

hope help.

javascript checkbox

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -