JS Add input function to select drop-down box

Source: Internet
Author: User

JavaScript uses the ParentNode.nextSibling.value implementation of this feature, you will actually find that there are two control elements on the 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 the Input, is actually using input to simulate the function of select, the idea is very novel, do not know how many people need select can enter the text function, the following is the detailed implementation code: Front-End resource sharing

. Code
  1. <div style="position:relative;" >
  2. <span style="Margin-left:100px;width:18px;overflow:hidden;" >
  3. <select style="width:118px;margin-left:-100px" onchange= "this.parentnode.nextsibling.value= This.value ">
  4. <option value="Sky blue"> Sky blue </option>
  5. <option value="Grass green"> Grass Green </option>
  6. <option value="water clearing"> Water clearing </option>
  7. </select></span><input name="box" style="width:100px;position:absolute;left:0px;" >

In this example, the CSS implements the positioning of the input box, and the JS implementation displays the value of the select selected by the user in input.

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.