2011-05-07 125 views
4

我使用了三個相互依賴的下拉列表。如何在java中保留下拉列表的選定值(struts)

用戶必須選擇第一個下拉列表。因此第二個列表將被填充。

然後用戶將再次選擇第二個下拉列表,然後第三個列表將被填充。

在第三個下拉列表選擇中,結果將填充。對於整個下拉列表,我使用的是Ajax。但對於最後一個下拉列表我使用action,所以我必須提交表單。

表單在搜索結果後返回。結果是正確的人口。

但是最後兩個下拉列表沒有填充選定的值。

所以對於我在頁面卸載時,如下

document.getElementById("laneid").text = '<%=laneID%>'; 

分配值我已經試過這也

document.getElementById("laneid").value = '<%=laneID%>'; 

befor從我打電話阿賈克斯行動回來以下拉式填充所有值。值將出現在請求變量'<%=laneID%>'中。

請幫我保留這些值。

我認爲jQuery可以在這種情況下提供幫助。但如果有任何其他解決方案,那麼請建議。

謝謝了。

回答

1

羅密,

的SELECT不能使用

document.getElementById("laneid").text = '<%=laneID%>'; 
document.getElementById("laneid").value = '<%=laneID%>'; 

相反,你應該使用訪問。

var selLaneID = document.getElementById("laneid"); // get the element 
selLaneID.options[selLaneID.selectedIndex].value; // gives the value of selected option 
selLaneID.options[selLaneID.selectedIndex].text; // gives the selected text 

jQuery中:

$("#laneid").val(); // gives value of selected text 
$("#laneid option:selected").text(); // gives the selected text 
$("#laneid").text(); // gives ALL text in SELECT 
$("#laneid").val("val3"); // selects the option with value="val3" 
如果你想在JavaScript設置的dropdon值,使用JQuery方法是最容易

使用Struts,您還可以使用<html:select><html:optionsCollection>標籤填充和選擇下拉列表。檢查出來。

相關問題