Change Text Box Value Based on Select Input with Selected Attribute

后端 未结 7 1137
再見小時候
再見小時候 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-14 23:57

    Give this one a try: http://jsfiddle.net/ufomammut66/mw4dY/

    Basically onload I'm just selecting an option by the value, setting it to selected and then calling the change event. Your change event takes care of the rest.

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

提交回复
热议问题