I am working on a project to practice form validation in javascript and HTML and I can't seem to get the addEventListener to work. I need 3 one to check if all required forms are filled when the submit button is clicked, one to check if the input they put into the phone is correct, and another to check that the choose one of the radio button options. I know functions work, I just can't get the addEventListener to trigger. Here are the events:
document.getElementById("_submit").addEventListener("click", submit(),useCapture);
document.getElementById("phone").addEventListener("input", checkInputPhone(), useCapture);
document.getElementByName("type").addEventListener("submit", checkType(), useCapture);
Here are HTML:
<label>Phone Number: Please enter in this format-(XXX-XXX-XXXX)*required</label>
<input type="tel" id="phone" name="phone" required pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}">
<p id = "_phone" name = "errorMessage"></p>
<div id="credit_type">
<h3>Credit Card type:</h3>
<input type="radio" id="visa" name="type" value="visa">
<label for="visa">Visa</label>
<input type="radio" id="master" name="type" value="master">
<label for="master">Mastercard</label>
<input type="radio" id="american" name="type" value="american">
<label for="american">American Express</label>
<p id = "_type"></p>
</div>
<button type="submit" id = "_submit">Validator</button>
<button type="buttom" onclick = "reset()">Reset</button>
<p id="sub" name = "errorMessage"></p>
and here are the functions:
function submit(){
getAddress();
getName();
getCreditInfo();
document.getElementById("total").innerHTML = total;
}
function checkInputPhone(){
var input = document.getElementById("phone").value;
if(!input.checkValidity()){
document.getElementById("_phone").innerHTML = "Not a valid input";
}
}
function checkType(){
var input = document.getElementByName("type").value;
if (input == ""){
document.getElementById("_type").innerHTML = "A type selection is required.";
}
}