How to get value of selected radio button?

前端 未结 28 2308
温柔的废话
温柔的废话 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:56

    https://codepen.io/anon/pen/YQxbZJ

    The HTML

    Fixed Rate Variable Rate Multi Rate

    The JS

    var x ,y;
    var x = document.getElementById("check");
    function boom()
    {
    if (document.getElementById("x1").checked)
      y = document.getElementById("x1").value;
    
    else if(document.getElementById("x2").checked)
      y = document.getElementById("x2").value;
    
    else if (document.getElementById("x3").checked)
      y = document.getElementById("x3").value;
    else
      y = "kuch nhi;"
    x.innerHTML = y;
    }
    
    var z = document.getElementById('rdio');
    z.addEventListener("click", boom);`
    

提交回复
热议问题