jquery Select to assign a value to the text box in the Select drop-down box

Source: Internet
Author: User

jquery Select the Select drop-down box to assign a value to the text box, the value of the first drop-down box cannot be assigned to the TextBox

Because select selects the first item by default ... When you select the first item, the onchange event is not fired. So you can't assign to a text box

Workaround.

Select drop-down box set the first item to make a useless placeholder option

<script type= "Text/javascript" > Function changeselect (obj) {var _this = obj; $ ("#goods_private_attr"). Val ($ (_this). Val ());
_this.options[0].selected = true; //The Select is initialized to the first one. so that the text box is modified and the same is selected again.
} </script>
 <select id= "sel"  style= "float:right; width:200px; z-index:1; position: absolute; left:110px; top:3px; height:22px; "  onchange= "changeselect (this);"                      <option value= ""  style= "Display:none" ></ Option>                      <option value= "111" >111</option>                    <option value= "222" > 222</option>                    <option value= "333" >333</OPTION></SELECT> 

This overlaps with the text box and the above select. But the Z-index is higher.
<input type= "text" id= "goods_private_attr" name= "goods_private_attr" value= "" style= "position:absolute; width:175px; height:12px; left:111px; top:6px; Z-index:2; border:0; "/>

jquery Select to assign a value to the text box in the Select drop-down box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.