JSP page drop-down list

Source: Internet
Author: User

During web development, we often encounter functional requirements for information modification. In this case, we provide a JSP page for users to display the current information and allow users to reset new values. On this page, the drop-down list is indispensable. As for its processing method, I used to think about one method. The idea is as follows: Set a hidden field on the page to save the value passed in the background. Then, output the drop-down list on the page, in this case, its value is the default value, that is, the first item. In the JS Code segment, obtain the value in the hidden field and judge in the loop whether it is equal to the ID value of the drop-down item, if they are equal, the selected status is set. Because this method is too cumbersome, the code will not be pasted. The following are two common solutions.
Method 1:

<Select id = "user_id" name = "user_id"> <C: foreach items = "$ {users}" Var = "U"> <option value = "$ {u. id} "<C: If test =" $ {user. user_id = u. id} "> <C: Out value =" selected "/> </C: If >$ {u. name} </option> </C: foreach> </SELECT>

Method 2:

<Select id = "projectporperty" name = "projectporperty"> <option value = "1"> Implementation </option> <option value = "0"> R & D </option> </SELECT> <SCRIPT> form. projectporperty. value = '$ {user. projectporperty} '; </SCRIPT>

Each of the above two methods has advantages and disadvantages. Select one based on your needs!

Related Article

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.