简体   繁体   中英

Need another dropdown menu when first drop down selects a value using spring tag in jsp

I have my jsp file ,in which I need 2 drop downs.If I select 1st drop down ,based on value,it should display another drop down. I am using springMVC and jstl in jsp.

here is my code for generate.jsp

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@taglib uri="http://www.springframework.org/tags/form" prefix="sp" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Generation</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> jQuery(document).ready(function(){ $("#selectEmp").on('change',function(){ if(this.val =='2') { $("#dept").css('display','block'); $("#dept").show(); } else { $("#dept").hide(); } }); }); </script> </head> <body> <div class="dropdown generate-file">Type :<sp:select id="selectEmp" path="type" name="selectEmp"> <option value="1">All</option> <option value="2">Department</option> <option value="3">Individual</option> </sp:select></div><br/><br/> <div class="dropdown generate-file" id="dept" style="display:none;"> Department:<sp:select path=""><span class="caret"></span> <option value="">R and D</option> <option value="">Development</option> <option value="">Sales</option> <option value="">Admin</option> <option value="">HR</option> <option value="">Marketing</option> <option value="">CRM</option> <option value="">Finance</option> </sp:select> </div> </body> </html> 

You need to use $(this).val() == '2' .

$dept = $("#dept");
$(this).val() == '2' ? $dept.show() : $dept.hide();

 jQuery(document).ready(function() { $("#selectEmp").on('change', function() { $dept = $("#dept"); $(this).val() == '2' ? $dept.show() : $dept.hide(); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <div class="dropdown generate-file">Type : <select id="selectEmp" name="selectEmp"> <option value="1">All</option> <option value="2">Department</option> <option value="3">Individual</option> </select> </div> <br/> <br/> <div class="dropdown generate-file" id="dept" style="display:none;"> Department: <select path=""><span class="caret"></span> <option value="">R and D</option> <option value="">Development</option> <option value="">Sales</option> <option value="">Admin</option> <option value="">HR</option> <option value="">Marketing</option> <option value="">CRM</option> <option value="">Finance</option> <select> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM