How to get value of selected radio button?

前端 未结 28 2713
温柔的废话
温柔的废话 2020-11-22 03:51

I want to get the selected value from a group of radio buttons.

Here\'s my HTML:

28条回答
  •  轮回少年
    2020-11-22 04:39

    directly calling a radio button many times gives you the value of the FIRST button, not the CHECKED button. instead of looping thru radio buttons to see which one is checked, i prefer to call an onclick javascript function that sets a variable that can later be retrieved at will.

    
    

    which calls:

    var currentValue = 0;
    function handleClick(myRadio) {
        currentValue = myRadio.value;
        document.getElementById("buttonSubmit").disabled = false; 
    }
    

    additional advantage being that i can treat data and/or react to the checking of a button (in this case, enabling SUBMIT button).

提交回复
热议问题