javascript - Getting value of checked radio button by name of radio button? -


i looked @ questions still can't it. how value of these radio buttons? not supposed name? html:

 <label 'planet'>planet:</label> <br>   <input id ='mercury' type ='radio' name='planets' value='mercury'>mercury<br>    <input id ='venus'type ='radio' name='planets' value='venus'>venus<br>   <input id ='earth'type ='radio' name='planets' value='earth'>earth<br>   <input id ='mars'type ='radio' name='planets' value='mars'>mars<br>   <input id ='jupiter'type ='radio' name='planets' value='jupiter'>jupiter<br>   <input id ='saturn'type ='radio' name='planets' value='saturn'>saturn<br>   <input id ='uranus'type ='radio' name='planets' value='uranus'>uranus<br>   <input id ='neptune'type ='radio' name='planets' value='neptune'>neptune<br><br>    <button id='submit'>submit</button> 

javascript:

$('#submit').on('click',function(){   $("input:radio").attr("checked", false);   var age = document.getelementbyid('age');   age.value=' ';    var checked = document.getelementsbyname('planets').checked.value;     alert(checked); }); 

$("input[name='planets']:checked").val()

jsfiddle demo

edit:

i see line in submit handler, uncheck radio buttons, don't it..

$("input:radio").attr("checked", false);


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -