Мне удалось отобразить входное значение для другого ввода, используя форму HTML. Я хочу отображать входные значения в элементах selectoption
вместо ввода 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" />
Но я хочу отобразить указанные выше значения myinput2 myinput4 в приведенных ниже значениях параметров в поле выбора, когда введены данные на myinput1 и myinput3.
<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>
проверить это
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>
попробуйте использовать
onkeyup = "myChangeFunction1(this)"
вместоonchange = "myChangeFunction1(this)"