How to get the selected radio button’s value?

后端 未结 18 1607
北海茫月
北海茫月 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条回答
  •  梦毁少年i
    2020-11-22 01:11

    In case someone was looking for an answer and landed here like me, from Chrome 34 and Firefox 33 you can do the following:

    var form = document.theForm;
    var radios = form.elements['genderS'];
    alert(radios.value);
    

    or simpler:

    alert(document.theForm.genderS.value);
    

    refrence: https://developer.mozilla.org/en-US/docs/Web/API/RadioNodeList/value

提交回复
热议问题