I need to create a JavaScript function that will run only if three specific variables are typed into a form.
In other words, I'd like to take a function like this example, and instead of just requiring "John" in the first_name field, It would also need "Smith" in the last_name field and "MIT" in the "school" field.
function validateForm (){
formElement = document.getElementById('myform');
isFormValid = formElement.checkValidity();
if (isFormValid){
var inputElement = document.getElementById('first_name');
var inputValue = inputElement.value
if (inputValue == 'John'){
alert ("Blahblahblah");
}
}
}
I guess ultimately I want to add the three elements so that the inputValue = "JohnSmithMIT", so all three variables can be validated.
I tried this to no avail:
function validateForm (){
formElement = document.getElementById('myform');
isFormValid = formElement.checkValidity();
if (isFormValid){
var inputElement = document.getElementById('first_name')+('last_name')+('school');
var inputValue = inputElement.value
if (inputValue == 'JohnSmithMIT'){
alert ("Blahblahblah");
}
}
}
I'm pretty new at this, any help would be appreciated. Thank you.
formElement.first_name(assuming the name and ID match), which is faster and less to type than using getElementById.