Question: How would I add form validation to my javascript? I want the user to get an alert message for an invalid input if they don't

How would I add form validation to my javascript? I want the user to get an alert message for an invalid input if they don't list the car Ford or Audi and they list it as it being (ford, f0rd) or (audi or aUdi)

This is my html code:

Am I the right salesperson for you? Which is your favorite brand of automobile?

  • Audi
  • Ford

Enter your selection in the input below.

This is my javascript:

function carsPage2() { var cars = ["Audi", "Ford"]; var userInput = document.getElementById("in").value; var output; if (userInput == cars[0]) { output = "Yes, I am the right salesperson for you! See me about our current Toyota deals!"; } else if (userInput == cars [1]) { output = "No, I am not the right salesperson for you. Please see other salesman for our current Ford deals."; } else { output = "We do not carry that brand of automobile."; } document.getElementById("user").innerHTML = output; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!