<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Airline Reservation System</title>
<form id="ourForm" name="myform" >
<table>
<tr><td>Enter 1 for Economy Seat, 2 for First Class</td><td><input type="text" name="box1" size="5"/></td></tr>
<tr><td>Result</td><td><textarea name = "textarea" rows="40" cols="70"/></textarea></td></tr>
<tr><td><input type="button" value="Submit" name="button1"onClick="startArray()"></td>
<td><input type="reset" value="Clear" name="button2"></td></tr></table>
</FORM>
<HEAD>
<script type = "text/javascript">
<!--
var input;
var secondInput;
var element;
var secondElement;
var firstCount = 0;
var economyCount = 0;
var seats = [ ,0,0,0,0,0,0,0,0,0,0]; //allocate 10-element Array
function startArray()
{
formRef = document.getElementById;
input = document.myform.box1.value;
formRef.box1.value="";
for(var i=0; i<11; i++)
{
if (input == 1 || input = 2)
{
element = linearSearch(seats);
if (element == -1 && input == 1)
{
document.myform.textarea.value=("The First Class is already fully booked\n");
secondQuestion(seats);
}
else if (element == -1 && input == 2)
{
document.myform.textarea.value=("The Economy Class is already fully booked\n");
secondQuestion(seats);
}
else
boardingPass(input);
}
//to terminate the program
else
{
document.myform.textarea.value=("Bye-bye!");
System.exit(0);
}}}
function linearSearch(theArray)
{
if (input == 1)
{
for (var n=0; n<6 ; n++)
if (theArray [n] == 0)
return n;
}
else if (input == 2)
{
for (var n=6; n<11 ; n++)
if (theArray [n] == 0)
return n;
}
return -1;
}
function boardingPass(theInput)
{
if (input ==1)
{
document.myform.textarea.value=("----------BOARDING PASS----------<br/>");
document.myform.textarea.value=("You are allocated in the First Class<br/>");
document.myform.textarea.value=("Your seat number is "+ element+"<br/>");
document.myform.textarea.value=("-----------------------------------------<br/>");
seats[element]= 1;
firstCount++;
}
else if (input ==2)
{
document.myform.textarea.value=("----------BOARDING PASS----------<br/>");
document.myform.textarea.value=("You are allocated in the Economy Class<br/>");
document.myform.textarea.value=("Your seat number is "+ element +"<br/>");
document.myform.textarea.value=("-----------------------------------------<br/>");
seats[element]= 1;
economyCount++;
}
}
function secondQuestion(theArray)
{
if (input == 1)
{
for (var n=6; n<11 ;n++)
{
if (theArray [n] == 0)
{
secondInput = document.myform.textarea.value=("Do you want to move to Economy Class? (If YES, please press 1. If NO, please press 2)","0");
if ( secondInput == 1)
{
input = 2;
element=linearSearch(seats);
document.myform.textarea.value=("You have been allocated to Economy Class<br/>");
boardingPass(input);
break;
}
else if (secondInput == 2)
{
document.myform.textarea.value=("Next flight leaves in 3 hours<br/>");
break;
}}}}
else if (input == 2)
{
for (var n=0; n<6 ;n++)
{
if (theArray [n] == 0)
{
secondInput = document.myform.textarea.value=("Do you want to move to First Class? (If YES, please press 1. If NO, please press 2)","0");
if ( secondInput == 1)
{
input = 1;
element=linearSearch(seats);
document.myform.textarea.value=("You have been allocated to First Class<br/>");
boardingPass(input);
break;
}
else if (secondInput == 2)
{
document.myform.textarea.value=("Next flight leaves in 3 hours<br/>");
break;
}}}}}
//-->
</script>
</head>
</body>
</html>
well i got this far and it keeps kicking me out of the initial input loop, why?