-2
所以我的程序應該接收來自Java Beans文件的輸入,該文件然後將該數據輸出到現有的選擇框,但是隻有當另一個選擇框選擇的值改變時。我怎樣才能做到這一點?這裏是我現有的代碼:如何在另一個選擇值更改時更新選擇?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Dropdown List</title>
</h:head>
<body>
<select id="mySelect" onchange="myFunction()">
<h:outputText value="#{helloWorld.getResultSet1()}" escape="false" />
<f:attribute name="action" value="1" />
</select>
<br />
<h:form id="formId">
<h:inputHidden id="x" value="#{helloWorld.text}" />
<h:commandButton id="y" value="read" action="#{helloWorld.submit()}">
<f:ajax execute="@form" />
</h:commandButton>
</h:form>
<div id="i">
<select id="mySelect1">
</select>
</div>
<p id="u"></p>
<script>
var x1 = document.getElementById("mySelect1");
x1.style.display = 'none';
document.getElementById("formId:y").style.display = 'none';
function myFunction() {
var x = document.getElementById('mySelect').value;
document.getElementById("formId:x").value = x;
document.getElementById("formId:y").click();
var t = "#{helloWorld.getResultSet2()}";
document.getElementById("u").innerHTML = t;
x1.style.display = 'block';
}
</script>
</body>
</html>
請參閱對其他問題的評論...... – Kukeltje