ProgramKitkat
ProgramKitkat

Reputation: 395

Why doesn't it work for rows 7-13

The program is a Seat reservation program rows 1 and 2 are first class, row 3-9 are business class and rows 10 through 13 are economy. They are initialized to * and become X when it is reserved. and alert you if the seat is already filled. The rows will fill for the first 6 rows but it ignores request for row 7 and beyond. But i know it goes to the appropriate function because if i request Economy with row 3 (which is invalid) it alerts me. But if i ask for first class with row7 it will act like nothing has been requested. It won't let me post the html code but it will display as row1-13 on the left and A - F across the top. I use drop down list and I set the values to the corresponding for the options to their corresponding spot in a the 2-d array (eg if i select row 5 and seat c the value of row 5 is 5 and the value of C is 3)

var rowSeat;

function start()
{
    rowSeat = new Array(14);

    for(var i = 0; i <rowSeat.length; i++)
    {
        rowSeat[i] = new Array(7);
    }
    var j = 65;
    for(var i = 1; i <rowSeat[0].length; i++)
    {
        rowSeat[0][i] = String.fromCharCode(j);
        j++;
    }
    rowSeat[0][0] = " ";
    for(var i = 1; i <rowSeat.length; i++)
    {
        rowSeat[i][0] = "Row "+i;

    }
    for(var i = 1; i <rowSeat.length; i++)
    {
        for(var j = 1; j <rowSeat[i].length; j++)
        {
            rowSeat[i][j] = "*";

        }
    }
    display();
    var subButton = document.getElementById("submitButton");
    subButton.addEventListener("click", assign, false);
}


function display()
{
    var results = "";
    results+="<table>"
    for(var i in rowSeat)
    {
            results+="<tr>";
        for(var j in rowSeat[i])
        {
            results += "<td>" +rowSeat[i][j]+ "</td>";
        }
        results += "</tr>";
    }
    results+="</table>"
    var show2 = document.getElementById( "show2" );
    show2.innerHTML = results;
}

function assign()
{
    var inputField = document.getElementById("classAssign");
    var classType = inputField.options[inputField.selectedIndex].value;

    if (classType == "FirstClass")
    {
    fClassSearch();
    }
    else if (classType == "Business")
    {
    bClassSearch();
    }
    else 
    {
    eClassSearch();
    }

    display();


}
function fClassSearch(){

    var inputField = document.getElementById("seatAssign");
    var seat = inputField.options[inputField.selectedIndex].value;

    var inputField2 = document.getElementById("rowAssign");
    var row = inputField.options[inputField2.selectedIndex].value;
    var test = document.getElementById( "test" );
    test.innerHTML = row +"&nbsp;&nbsp;&nbsp;"+ seat;

    if (row >2){
        var show2 = document.getElementById( "show" );
    show.innerHTML = "Invalid choice only row 1 and 2 are First Class";
    }
    else {
        if(rowSeat[row][seat] == "*")
        {
            rowSeat[row][seat] = "X";
            show.innerHTML = "Your Seat choice was accepted and Reserved";
        }
        else{
            show.innerHTML = "Your choice was already reserved please make another choice";
        }
    }
}
function bClassSearch(){
    var inputField = document.getElementById("seatAssign");
    var seat = inputField.options[inputField.selectedIndex].value;
    var inputField2 = document.getElementById("rowAssign");
    var row = inputField.options[inputField2.selectedIndex].value;

    if (row <3 ||row >9){
        var show2 = document.getElementById( "show" );
    show.innerHTML = "Invalid choice only row 3 through 9 are BusinessClass";
    }
    else {
        if(rowSeat[row][seat] == "*")
        {
            rowSeat[row][seat] = "X";
            show.innerHTML = "Your Seat choice was accepted and Reserved";
        }
        else{
            show.innerHTML = "Your choice was already reserved please make another choice";
        }
    }


}
function eClassSearch(){
    var inputField = document.getElementById("seatAssign");
    var seat = inputField.options[inputField.selectedIndex].value;
    var inputField2 = document.getElementById("rowAssign");
    var row = inputField.options[inputField2.selectedIndex].value;
    var show1 = document.getElementById( "show" );

    if (row <10){

    show1.innerHTML = "Invalid choice only rows 10 through 13 are Economy Class";
    }
    else {
        if(rowSeat[row][seat] == "*")
        {
            rowSeat[row][seat] = "X";
            show.innerHTML = "Your Seat choice was accepted and Reserved";
        }
        else{
            show.innerHTML = "Your choice was already reserved please make another choice";
        }
    }


    }


    window.addEventListener("load",start, false);

   </script>

Upvotes: 0

Views: 83

Answers (1)

Hakobo
Hakobo

Reputation: 26

var row = inputField.options[inputField2.selectedIndex].value;

inputField.options should be inputField2.options

inputField.options only goes to 6 because you only have 6 seats wide, but you are trying to look at the row in the seat list.

Upvotes: 1

Related Questions