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!