简体   繁体   中英

how to get value from selected radio button

sir, i have a form input like input text and radio button. how to get the value of selected radio button, and put that value to the input type text.

heres jsfiddle, https://jsfiddle.net/czw71dfk/2/

    <div id="gender" class="form-inline">
  <div class="form-group">
    <label for="">I Sign up as</label>
    <input #id="place" type="text" class="form-control" readonly/>
    <div class="radio-inline">
      <label class="label_item" for="radioMale">
        <input type="radio" class="radio_item" value="male"  name="gender" id="radioMale">
      </label>
      <p class="text-center colorGrey">Male</p>
     </div>
    <div class="radio-inline">
      <label class="label_item" for="radioFemale">
        <input type="radio" class="radio_item" value="female"  name="gender" id="radioFemale">
      </label>
      <p class="text-center colorGrey">Female</p>
    </div>
    <div class="radio-inline">
      <label class="label_item" for="radioKids">
        <input type="radio" class="radio_item" value="Kids" name="gender" id="radioKids">
      </label>
      <p class="text-center colorGrey">Kids</p>
    </div>
  </div>
</div>

$('#gender input').on('change', function() {
    var gender = $( this ).val();
   $("#place").val( gender );
});

Change #id="place" To id="place" https://jsfiddle.net/czw71dfk/4/

<input #id="place" type="text" class="form-control" readonly/>

To

<input id="place" type="text" class="form-control" readonly/>

HTML problem #id="place" ,

And must be using on change;

$(document).ready(function(){

  $('input[name=gender]').on('change', function() {
    var gender = $( this ).val();
     $("#place").val( gender );
  });

});

JSFiddle.net Example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM