How to get value of selected radio button?

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

    I used the jQuery.click function to get the desired output:

    $('input[name=rate]').click(function(){
      console.log('Hey you clicked this: ' + this.value);
    
      if(this.value == 'Fixed Rate'){
        rate_value = $('#r1').value;
      } else if(this.value =='Variable Rate'){
       rate_value = $('#r2').value;
      } else if(this.value =='Multi Rate'){
       rate_value = $('#r3').value;
      }  
    
      $('#results').innerHTML = rate_value;
    });
    

    Hope it helps.

提交回复
热议问题