I'm currently trying to catch input data from a form and storing that data into an array of objects that can then summarize the data caught in the console. On top of this, I'm trying to run the function to store that data using a traditional DOM event handler per the instructions for my assignment.
The end goal with the JS is to use var t to get the element of the submit button by the ID 'contactSubButton' and run the function contactInfo onsubmit...
However, no matter what I try I get this message in the console at the line for the 't.addEventListener'....
Uncaught TypeError: Cannot read property 'addEventListener' of null
var t = document.getElementById("contactSubButton");
t.addEventListener('click', contactInfo());
function contactInfo(fName, lName, email, country, subject) {
fName = document.getElementById('fname').value;
lName = document.getElementById('lname').value;
email = document.getElementById('email').value;
country = document.getElementById('country').value;
subject = document.getElementById('subject').value;
for (i = 0;; i++) {
var subInfo = [fName, lName, email, country, subject]
}
console.log('Your submission details are:' < br > 'First Name: ' + fName)
}
<div id="form">
<form>
<label for="fname">First Name</label>
<input type="text" id="fname" name="firstname" placeholder="Your first name...">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lastname" placeholder="Your last name....">
<label for="email">Email Address</label>
<input type="email" id="email" name="email" placeholder="Please enter your email...">
<label for="country">Country</label>
<select id="country" name="country">
<option value="usa">United States</option>
<option value="canada">Canada</option>
<option value="mexico">Mexico</option>
</select>
<label for="subject">Subject</label>
<textarea id="subject" name="subject" placeholder="How can we help?"></textarea>
<input type="submit" value="Submit" id="contactSubButton">
<input type="reset" value="Reset Form">
</form>
</div>
for (i = 0;; i++) {contactInfo(fName, lName, email, country, subject) {t.addEventListener('click', contactInfo);without the()var subInfo = [fName, lName, email, country, subject]