How can I make it so a different result occurs depending on an input?

I have the following code, and I was wondering instead of making it so that if any variable inside the array is entered it will bring you to index.php, I want it so if the first is entered it will bring you to 1.html, if 2 is entered it will bring you to 2.html etc.
I
s this possible?

The HTML code:

<center>
    <form
     name="myForm"
     onsubmit="return validateForm()"
     method="post"
    >
        <h1 style = "color:white;">Enter code </h1>
        <input type="text" name="value" style="padding: 5px; border-radius: 6px; border: 0px solid transparent;"/>
        <br><br>
        <input type="submit" class = "ex" value="Enter/submit" style="border-radius: 6px; font-size: 18px;display: inline-block; padding: 20px; border: none; background-color: royalblue; color: white;"/>
    </form>
</center>

The JavaScript code:

var cars = ["Saab", "Volvo", "BMW"];
function validateForm() {
    var x = document.forms["myForm"]["value"].value;
    if (cars.indexOf(x) == -1) {
        alert("no car entered");
        return false;
    }

    var x = document.forms["myForm"]["value"].value;
    if (cars.indexOf(x) != -1) {
        window.location.href = "index.php";
        return false;
    }
}

16 thoughts on “How can I make it so a different result occurs depending on an input?”

Leave a Comment