I am trying to write a short javascript program for a college class. It is a program that is an airline reservation system for a small airline. The aircraft in question has 10 seats, 5 for first class and 5 for economy class. the program picks a random seat for what ever class you choose and if the seat is chosen again, the program should tell you "that seat is taken".
this is my code so far
***************
<html>
<head>
<title>Airline Reservations System</title>
<script type="text/javascript">
<!--
function selectseat()
{
var typeseat = document.myForm.typeseat.value;
var seats = new Array(10)[0,0,0,0,0,0,0,0,0,0];
if (typeseat == 1)
{
var seat = "First Class seat ";
var find = Math.floor(1 + Math.random() * 5);
choice1=find;
//1document.write("find equals " +find);
if (seats[find]!=0)
document.write(""+seat+ " " + choice1+ " is taken<br />");
else
document.write("the seat selected is " + seat + " number " + choice1);
}
else
{
var seat = "Economy seat ";
var choice2 = Math.floor(1 + Math.random() * 5) + 5;
//document.write(""+seat+ " " + choice2+ " is taken<br />");
document.write("the seat selected is " + seat + " number " + choice2);
}
}
//-->
</script>
</head>
<body>
<form name = "myForm" action = "">
Please type 1 for "First Class" <br />
Please type 2 for "Economy"<br />
<input name = "typeseat" type = "text"/><br />
<input name = "calculate" type = "button" value = <!-- m --><a class="postlink" href="http://www.webdeveloper.com/forum/archive/index.php/">http://www.webdeveloper.com/forum/archive/index.php/</a><!-- m -->"Submit" onclick = "selectseat()" />
</form>
</body>
</html>
***********
my problem is that when i read in the seat for first class, i want the seats array to change to 1 for the seat that is taken. When i run this code I get an error at line 24, char 3 which says "undefined is null or not an object"...
Thanks in advance for the help
Johnny
this is my code so far
***************
<html>
<head>
<title>Airline Reservations System</title>
<script type="text/javascript">
<!--
function selectseat()
{
var typeseat = document.myForm.typeseat.value;
var seats = new Array(10)[0,0,0,0,0,0,0,0,0,0];
if (typeseat == 1)
{
var seat = "First Class seat ";
var find = Math.floor(1 + Math.random() * 5);
choice1=find;
//1document.write("find equals " +find);
if (seats[find]!=0)
document.write(""+seat+ " " + choice1+ " is taken<br />");
else
document.write("the seat selected is " + seat + " number " + choice1);
}
else
{
var seat = "Economy seat ";
var choice2 = Math.floor(1 + Math.random() * 5) + 5;
//document.write(""+seat+ " " + choice2+ " is taken<br />");
document.write("the seat selected is " + seat + " number " + choice2);
}
}
//-->
</script>
</head>
<body>
<form name = "myForm" action = "">
Please type 1 for "First Class" <br />
Please type 2 for "Economy"<br />
<input name = "typeseat" type = "text"/><br />
<input name = "calculate" type = "button" value = <!-- m --><a class="postlink" href="http://www.webdeveloper.com/forum/archive/index.php/">http://www.webdeveloper.com/forum/archive/index.php/</a><!-- m -->"Submit" onclick = "selectseat()" />
</form>
</body>
</html>
***********
my problem is that when i read in the seat for first class, i want the seats array to change to 1 for the seat that is taken. When i run this code I get an error at line 24, char 3 which says "undefined is null or not an object"...
Thanks in advance for the help
Johnny