在JSP Dropdown中使用JQuery变量 [英] Use JQuery variable in JSP Dropdown
问题描述
我正在构建我的第一个JSP接口,并且我已成功查询SQL Server数据库以填充下拉列表框,然后使用JQuery来获取从列表框中选择值并将其放在文本框中。我如何知道使用所选值来构建SQL语句来填充第二个列表框?基本上,第一个列表框选择的值会过滤第二个列表框中显示的值。
我使用了taglib指令来构建我的初始SQL查询。 />
<%@ taglib prefix =curi =http://java.sun.com/jsp/jstl/core%>
<%@ taglib prefix =sqluri =http://java.sun.com/jsp/jstl/sql%>
然后将其结果分配到第一个列表框;
Hi,
I am building my first JSP interface and I have successfully interrogated a SQL Server database to populate a dropdown list box and then using JQuery to take the selected value from the list box and place it in a text box. How do I know use the selected value to build a SQL statement to populate a second list box? Basically the value chosen by the first list box filters the values dispalyed in the second list box.
I have used the taglib directives to build my initial SQL query.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
Then assigned its results to the first list box;
<Select name="UserID" id="UserIDs" class="seluserval">
<c:forEach items="${result.rows}" var="st">
<option value="1"><c:out value="${st.USER_ID}"/></option>
</c:forEach>
</select>
然后使用以下JQuery将所选值放在文本框中;
Then used the following JQuery to place the selected value in the text box;
var main = function() {
$('#UserIDs').on('change',function(){
var selUser = $('#UserIDs :selected').text();
$('#selecteduservalue').val(selUser);
});
};
$(document).ready(main);
推荐答案
{result.rows} var = st >
< < span class =code-leadattribute>选项 value = 1 > < c:out value =
{result.rows}" var="st"> <option value="1"><c:out value="
{st.USER_ID} / > < / option >
< / c:forEach >
< < span class =code-leadattribute> / select >
{st.USER_ID}"/></option> </c:forEach> </select>
然后使用以下JQuery将所选值放在文本框中;
Then used the following JQuery to place the selected value in the text box;
var main = function() {
(' #UserIDs')。on(' change',function(){
var selUser =
('#UserIDs').on('change',function(){ var selUser =
这篇关于在JSP Dropdown中使用JQuery变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!