jQuery Change Input text upon selection of radio button

前端 未结 5 498
借酒劲吻你
借酒劲吻你 2021-01-28 04:26

Trying to get the value=\"\" of to change upon selection of a radio button. So if the user

相关标签:
5条回答
  • 2021-01-28 04:54

    Really Simple fiddle.

    Using code:

    $(document).ready(function(){
      $("input[type=radio]").click(function(){
         $("#it").val(this.value);
      }); 
    });
    

    And HTML:

    <input type="text" id="it" value="">
    <input type="radio" name="hey" value="one">
    <input type="radio" name="hey" value="two">
    <input type="radio" name="hey" value="three">
    

    This demonstrates the concept of how to do it.

    0 讨论(0)
  • 2021-01-28 04:54

    it will bind an event handler change of all inputs inside the form searchSelect, with name option1 and of type radio.

    $(function() {
        $('#searchSelect input[name="option1"]:radio').change(function() { 
            $('.box').val('Enter a ' + this.value); 
        });
    });
    

    to learn more about the change event check out the jQuery documentation.

    0 讨论(0)
  • 2021-01-28 05:00
    $(document).ready(function() {
        $("input[name=option1]:radio").click(function(eventObj) {
            $("input[name=searchQuery]").val("Enter a " + $(eventObj.target).val());
        });
    });
    
    0 讨论(0)
  • 2021-01-28 05:06

    Give the radio input a class of "option" or call it what ever

    <input type='radio' class='option' name='option' value='First Name'>
    

    Then the jquery:

    $('.option').click(function(){
       var thisRadio = $(this).val();
       $('.box').val(thisRadio);
    });
    
    0 讨论(0)
  • 2021-01-28 05:11
    <script type="text/javascript">
        $(document).ready(function(){
            $('#searchSelect input[type=radio]').change(function(){
                $('input.box').val('Enter ' + $(this).val());
            });
    
        });
    </script>
    
    0 讨论(0)
提交回复
热议问题