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);     } } 

http://jsfiddle.net/euerp/

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'); 

http://jsfiddle.net/euerp/2/


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -