我已成功使用 HTML 表單將輸入值顯示到另一個輸入。我想在選擇option元素中顯示輸入值,而不是輸入 3 和輸入 4。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<form action="" method="post">
<input
type="text"
id="myInput1"
onchange="myChangeFunction(this)"
placeholder="FIRST "
/>`
<input
type="text"
id="myInput3"
onchange="myChangeFunction1(this)"
placeholder="SECOND "
/><br />
上面的輸入顯示在下面的輸入欄位中。
<br />
<input type="text" id="myInput2" /> <br />
<input type="text" id="myInput4" />
但是當輸入 myinput1 和 myinput3 時,我想在選擇欄位中的以下選項值中顯示上面的 myinput2 myinput4 值。
<select>
<option>????? Here insert the value obtained at myInput2</option>
<option>??? Here insert the value obtained at myInput4</option>
</select>
<script type="text/javascript">
function myChangeFunction(input1) {
var p1 = document.getElementById("myInput2");
p1.value = input1.value;
}
function myChangeFunction1(input3) {
var p2 = document.getElementById("myInput4");
p2.value = input3.value;
}
</script>
</form>
uj5u.com熱心網友回復:
看看這個
function myChangeFunction(input1) {
var p1 = document.getElementById("option1");
p1.value = input1.value;
p1.innerHTML = input1.value
}
function myChangeFunction1(input3) {
var p2 = document.getElementById("option2");
p2.value = input3.value;
p2.innerHTML = input3.value
}
<form action="" method="post">
<input
type="text"
id="myInput1"
onkeyup="myChangeFunction(this)"
placeholder="FIRST "
/>`
<input
type="text"
id="myInput3"
onkeyup="myChangeFunction1(this)"
placeholder="SECOND "
/><br />
<select>
<option id="option1">????? Here insert the value obtained at myInput2</option>
<option id="option2">??? Here insert the value obtained at myInput4</option>
</select>
</form>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/445784.html
標籤:javascript html 形式
