passing HTML radio button value to a javascript variable -
this question has answer here:
i wonder if can me out, i'm stuck need write little code goes this.
question : did training? <input type="radio" name="q4" value="yes">yes <input type="radio" name="q4" value="no">no
whatever checked want pass javascript variable.
i think this:
var ch = document.getelementsbyname('q4'); (var = ch.length; i--;) { ch[i].onchange = function() { alert(this.value); } }
so subscribe to change event , can use selected value somehow.
alternatively can use queryselector (queryselectorall) methods. here example of how can checked element value:
var checked = document.queryselector('[name="q4"]:checked');
Comments
Post a Comment