我对贾瓦特来说非常新(头几天)。
创建航空公司预订表,希望显示一个座位价格,取决于乘客选择的等级。
不要确定如何从受扶养的下级文字中收回价值,从而可以形成一个阵列,将选定的价值与价格挂钩。 我的描述......
<script language="javascript" type="text/javascript">
function dropdownlist(listindex)
{
document.flightform.pitch.options.length = 0;
switch (listindex)
{
case "Economy":
document.flightform.pitch.options[0]=new Option("28","28");
document.flightform.pitch.options[1]=new Option("29","29");
break;
case "Biz":
document.flightform.pitch.options[0]=new Option("30","");
document.flightform.pitch.options[1]=new Option("32","");
break;
case "First":
document.flightform.pitch.options[0]=new Option("40","");
break;
}
return true;
}
var Seat_pitch= new Array ();
Seat_pitch["28"] = 400;
//etc.....
//etc.....
function getSeatpitch()
{
var Seatpitch=0;
var theForm = document.forms["flightform"];
var selectedpitch = theForm.elements["pitch"];
Seatpitch = Seat_pitch[selectedpitch.value];
return Seatpitch;
}
function calcTotal()
{
var Total = getSeatpitch() ;
//display the result
var divobj = document.getElementById( totalPrice );
divobj.style.display= block ;
divobj.innerHTML = "Your flight Total is £"+Total;
}
</script>
<htmL>
<body>
<label>Class type</label><br />
<select id="class" name= class onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);">
<option value="Economy">Economy</option>
<option value="Biz">Business</option>
<option value="First">First</option>
</select>
<br/><br/>
<script type="text/javascript" language="JavaScript">
document.write( <select name="pitch" id="pitch"></select> )
</script>
<div id="totalPrice"></div>
</html>
</body>