jQuery get select option id and change hidden input value

前端 未结 3 1990
长情又很酷
长情又很酷 2020-12-31 15:56

I have a form with a select list. Each option also contains a dynamic id, which I need to capture and then use that to change a hidden input\'s value. So basically take the

相关标签:
3条回答
  • 2020-12-31 16:33
    $('#size').change(function(){
       var id = $(this).find(':selected')[0].id;
       $('#changevalue').val(id);
    })
    
    0 讨论(0)
  • 2020-12-31 16:43
    $('select[name=item_options]').change(function(){
        $('input[name=item_options_name]').val($(this).val());
    };
    

    Or you can use ID selectors:

    $('#size').change(function(){
        $('#changevalue').val($(this).val());
    };
    
    0 讨论(0)
  • 2020-12-31 16:51
    <script type="text/javascript">
    
    $('#selectboxsize').change(function() {
    
        var id = $(this).find(':selected')[0].id;
    
        $('#getchangevalue').val(id);
    
    });
    
    </script>
    
    
    
    
    <select name="item_options" id="selectboxsize">
    
        <option value="20030" id="Universal">Universal (20030)</option>
    
        <option value="4545456" id="Medium">Medium (4545456)</option>
    
        <option value="15447" id="Large">Large (15447)</option>
    
    </select>
    
    <input type="hidden" name="item_options_name" value="Universal" id="getchangevalue" />
    
    0 讨论(0)
提交回复
热议问题