0

I am trying a javascript onchange method when i select some option in (To->("destination")) it dsn't set any value on price text box

<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>
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Rajesh
  • 1
  • You should do a [mcve]. – IncredibleHat Nov 15 '17 at 14:18
  • Possible duplicate of [Get selected value in dropdown list using JavaScript?](https://stackoverflow.com/questions/1085801/get-selected-value-in-dropdown-list-using-javascript) – Mad Myche Nov 15 '17 at 14:21
  • Since you are learning and writing new code... you should delve into jquery. It'll make your life so much easier ;) – IncredibleHat Nov 15 '17 at 14:21
  • The Select element's value is an index to the Option which is selected. As such, review this post: [Get selected value in dropdown list using javascript](https://stackoverflow.com/questions/1085801/get-selected-value-in-dropdown-list-using-javascript) – Mad Myche Nov 15 '17 at 14:23

1 Answers1

0

destination is a selectbox. to get what you are testing against in your switch statement, you would need to get the value like this:

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

the way you set the textbox value seems to work. try it out and let me know if it solved your problem!