-4
<input type="radio" id="radio1" name="radiobuttons" value="100">
<input type="radio" id="radio2" name="radiobuttons" value="200">
<input type="radio" id="radio3" name="radiobuttons" value="300">


<div id="selectedvalue"></div>

How do I get value of the checked radio button and output it as text inside "selectedvalue" ? The function should take the value of the checked radio on pageload and on input change.

The Process
  • 5,795
  • 3
  • 30
  • 41
Alexander Hein
  • 900
  • 3
  • 18
  • 39

2 Answers2

2
$(document).ready(function () {
    //apply the value on page ready (you probably don't have to wait until everyithing loads - otherwise chage it to window.load()
    $('#selectedvalue').html( $('input[name=radiobuttons]:checked').val() );

    //bind the change event to update the element
    $('input[name=radiobuttons]').on('change', function () {
        $('#selectedvalue').html( $(this).val() );
    });
});
zedling
  • 616
  • 9
  • 27
-1

You would do this by changing the text of your selectedvalue div.

Changing the HTML of your div may be unnecessary since you just want to display a number

$('#selectedvalue').text($('input[name=radiobuttons]:checked').val());

API -

Adjit
  • 9,708
  • 11
  • 49
  • 93