Get selected option from select element

后端 未结 12 981
温柔的废话
温柔的废话 2020-12-08 01:45

I am trying to get the selected option from a dropdown and populate another item with that text, as follows. IE is barking up a storm and it doesn\'t work in Firefox:

<
12条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 02:19

    The above would very well work, but it seems you have missed the jQuery typecast for the dropdown text. Other than that it would be advisable to use .val() to set text for an input text type element. With these changes the code would look like the following:

        $('#txtEntry2').val($('#ddlCodes option:selected').text());
    

提交回复
热议问题