gpt4 book ai didi

javascript - 我正在尝试使用 javascript onchange 方法,但我无法在文本框中获取值

转载 作者:行者123 更新时间:2023-11-28 02:38:15 26 4
gpt4 key购买 nike

我正在尝试一个 javascript onchange 方法当我在 (To->("destination")) 中选择某个选项时,它不会在价格文本框中设置任何值

<html>
<head>
<style>
div.newdiv
{
width:980;
background:url("");

}
div
{
display:inline-block;
color:black;
background-color:skyblue;
border:2px solid white;
box-shadow:3px 3px 3px white;
font-weight: 500;
color: #434248;
text-shadow: 0 1px rgba(white, .5);
border-radius: 40px;
width:500;
text-align:center;
}
h3
{
color:white;

}
h1
{
color:white;
background-color:lime;
border:2px solid white;
box-shadow:3px 3px 3px white;
}
body
{
background-color:white;
}
</style>
</head>
<body bgcolor=#CCCCCC>
<script>
function price()
{
var des = document.getElementById("destination").value;
switch (des)
{
case '700': document.getElementById("price").value="700";
break;

case '350': document.getElementById("price").value="350";
break;

case '550': document.getElementById("price").value="550";
break;

case '450': document.getElementById("price").value="450";
break;

default: document.getElementById("price").value="select
destination";
}

}

</script>
<div class=newdiv>
<div>
<h1>Online Booking Form</h1>
<h3><u>To reserve seats please complete and submit the booking form</u></h3>
<form name="f1" method="post" action="jsdropdown.php">

FirstName: <input type="text" name="fname" value="" placeholder=firstname>
<br><br>

LastName:<input type="text" name="lname" value="" placeholder=lastname><br>
<br>

Age: <input type="text" name="age" value="" placeholder=age><br><br>

E-mail: <input type="email" name="email" value=""
placeholder=example@gmail.com><br><br>

Phone Number:<select name="phno">
<option>+91</option>
<option>+12</option>
<option>+325</option>
<option>+487</option>
</select> - <input type="text" name="phno" value="" placeholder=phonenumber>
<br><br>

From:<input type="text" name="from" value="" placeholder=source><br><br>

To:<select id="destination" onchange="price()">
<option value="700">chennai</option>
<option value="350">ooty</option>
<option value="550">bangalore</option>
<option value="450">kerala</select>
<br><br>

Price:<input type="text" id="price" size="20" placeholder=price><br><br>

Bus Type:<select name="bustype">
<option>Ac</option>
<option>Non Ac</option></select><br><br>

Number Of Passengers:<input type="text" name="passenger" value=""
placeholder=passengers><br><br>

Total:<input type="text" name="total" value="" placeholder=total><br><br>

<input type="submit" align="center" name="book" value="BOOK YOUR TICKET">
</form></div></div>
</body>
</html>

最佳答案

目标是一个选择框。要在 switch 语句中获取要测试的内容,您需要获取如下值:

var destSelect = document.getElementById("destination");
var des = destSelect.options[destSelect.selectedIndex].value;

您设置文本框值的方式似乎可行。试试看,如果它解决了您的问题,请告诉我!

关于javascript - 我正在尝试使用 javascript onchange 方法,但我无法在文本框中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47309709/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com