This function is more practical, many cases we can use, in fact, the code is quite simple, you can also unlimited add any drop-down list box value, selected automatically displayed in the text box.
JavaScript uses ParentNode.nextSibling.value to implement this function, you will actually find that there are two control elements on the Web page, one is select, one is input, use CSS to overwrite the input on the Select, and then use JS to assign the value of the Drop-down box to Input, is actually using input to simulate the function of select, the idea is very novel, also do not know how many people need select can enter text function, the following is the detailed implementation code:
The code is as follows |
Copy Code |
<div style= "position:relative;" > <span style= "Margin-left:100px;width:18px;overflow:hidden;" > <select style= "width:118px;margin-left:-100px" onchange= "This.parentnode.nextsibling.value=this.value" > <option value= "Sky blue" > Azure blue </option> <option value= Green grass > Green Grass </option> <option value= "water clear" > Water qingqing </option> </select></span><input name= "box" style= "width:100px;position:absolute;left:0px;" > |
In this example, the CSS implementation input box positioning, JS implementation of the user selected select the value displayed in the input.
code is as follows |
copy code |
< html> <title> dropdown box selected values are automatically added to the text box </title> <body> <form name= "Form1" > <select name= menu1 "onchange=" document.form1.get.value=this.options[ This.selectedindex].value "> <option selected> Please choose </option> <option value=" Baidu "> Baidu </ option> <option value= "NetEase" > NetEase </option> <input type= "text" value= "" name= "get" id= "get" > br> </form> </body> |