Change Text Box Value Based on Select Input with Selected Attribute

后端 未结 7 1148
再見小時候
再見小時候 2020-12-14 23:03

I am attempting to change the value of a text input based on the user selecting a value from a pulldown. I have got it working using the following,



        
7条回答
  •  孤城傲影
    2020-12-15 00:01

    Try this,

    $(document).ready(function() {
    
        $("#name option").filter(function() {
            return $(this).val() == $("#firstname").val();
        }).attr('selected', true);
    
        $("#name").live("change", function() {
    
            $("#firstname").val($(this).find("option:selected").attr("value"));
        });
    });
    
    
    
    

提交回复
热议问题