How to get the selected radio button’s value?

后端 未结 18 1805
北海茫月
北海茫月 2020-11-22 00:57

I’m having some strange problem with my JS program. I had this working properly but for some reason it’s no longer working. I just want to find the value of the radio button

18条回答
  •  醉梦人生
    2020-11-22 01:20

    Here is an Example for Radios where no Checked="checked" attribute is used

    function test() {
    var radios = document.getElementsByName("radiotest");
    var found = 1;
    for (var i = 0; i < radios.length; i++) {       
        if (radios[i].checked) {
            alert(radios[i].value);
            found = 0;
            break;
        }
    }
       if(found == 1)
       {
         alert("Please Select Radio");
       }    
    }
    

    DEMO : http://jsfiddle.net/ipsjolly/hgdWp/2/ [Click Find without selecting any Radio]

    Source : http://bloggerplugnplay.blogspot.in/2013/01/validateget-checked-radio-value-in.html

提交回复
热议问题