How to get value of selected radio button?

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

    A year or so has passed since the question was asked, but I thought a substantial improvement of the answers was possible. I find this the easiest and most versatile script, because it checks whether a button has been checked, and if so, what its value is:

    
    
    
        
        Check radio checked and its value
    
    
    
        

    You can also call the function within another function, like this:

    function doSomething() {
        getRadioValue('theRadioGroupName');
        if (rdValue == '10') {
            // do something
        }
        else if (rdValue == 'noRadioChecked') {
            // do something else
        }  
    } 
    

提交回复
热议问题