我在jsp中有一个下拉列表:
<select name="tableName">
<c:forEach var="dropDown" items="${dropDown}">
<c:forEach var="valuesInRows" items="${dropDown.valuesInRows}">
<c:forEach var="valuesInRow" items="${valuesInRows}" varStatus="loop">
<c:if test="${loop.index %2 != 0}">
<option><c:out value="${valuesInRow}"></c:out></option>
</c:if>
</c:forEach>
</c:forEach>
</c:forEach>
</select>
然后我想将所选变量作为参数添加到同一jsp中的url中。怎么做?谢谢!
<s:url var="url_list" value="/spravochnik/list">
<s:param name="tableName" value="${tableName}"/>
</s:url>
由于某种原因,该按钮不起作用
答案 0 :(得分:0)
好吧,我建议您使用javascript,您可以将一个ID放入您的选择中并执行以下功能:
function myFunction(){
var select = document.getElementById("selectId");
var value = select.options[select.selectedIndex].text;
document.getElementById("newID").value = value;
}
然后如果您想在此处输入ID
<s:url var="url_list" value="/spravochnik/list">
<s:param id="newID" name="tableName" value=""/>
</s:url>
最后一件事是将事件添加到选择
<select name="tableName" onchange="myFunction()">
<c:forEach var="dropDown" items="${dropDown}">
<c:forEach var="valuesInRows" items="${dropDown.valuesInRows}">
<c:forEach var="valuesInRow" items="${valuesInRows}" varStatus="loop">
<c:if test="${loop.index %2 != 0}">
<option><c:out value="${valuesInRow}"></c:out> </option>
</c:if>
</c:forEach>
</c:forEach>
</c:forEach>
</select>