Home > Java > javaTutorial > What to use to write drop-down box in jsp page

What to use to write drop-down box in jsp page

(*-*)浩
Release: 2020-09-14 14:49:49
Original
16542 people have browsed it

How to write a drop-down box in a jsp page: first set a hidden field in the page to save the value passed from the background; then output the drop-down list in the page; finally get the hidden field in the js code snippet The value in and determine whether it is equal to the id value of the drop-down item in the loop.

What to use to write drop-down box in jsp page

#In the process of WEB development, we often encounter functional requirements for information modification. At this time, we provide the user with a JSP page that displays the current information and allows the user to reset the new value. In this page, a drop-down list is generally indispensable.

Recommended course: Java Tutorial.

As for its processing method, I have thought of one before. The idea is as follows: set a hidden field on the page to save the value passed from the background; then output the drop-down list on the page, and then its value It is the default, that is, the first item; get the value in the hidden field in the js code snippet and determine whether it is equal to the id value of the drop-down item in the loop. If equal, set the selected status of the item. Because this method is too cumbersome, the code will not be posted. The following are two commonly used processing methods.

Use label loop output drop-down box writing:

<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>
Copy after login

Method 2:

<select id="projectPorperty" name="projectPorperty">
	<option value="1">实施</option>
	<option value="0">研发</option>
</select>
<script>
	form.projectPorperty.value = '${user.projectPorperty}';
</script>
Copy after login

Static variable method:

<!-- 
 实现select标签回显 
-->  
1.<select name="curStatus"  value="${curStatus}">     
  <option value="0">-请选择-</option>     
  <option value="1" <c:if test="${&#39;1&#39; eq curStatus}">selected</c:if> >男</option>     
  <option value="2" <c:if test="${&#39;2&#39; eq curStatus}">selected</c:if> >女</option>  
 </select>
Copy after login

The above is the detailed content of What to use to write drop-down box in jsp page. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template