Trouble with .addEventListener
having trouble figuring out what I am doing wrong in this snippet
const email = document.getElementById('email');
const confirm_email = document.getElementById('confirm_email');
const submit = document.getElementById('submit');
const ok = document.getElementById('ok');
const alert_box = document.getElementById('alert_box');
submit.addEventListener('click', function(){
if (email !== confirm_email) {
alert_box.style.display = 'flex';
event.preventDefault()
}
});
I thought it would function as it would grab my inputs from my form after I clicked my submit button and if the email and confirm_email didn't match it would change my display state but it will change the display state even if it does match.
--SOLVED--
submit.addEventListener('click', function(){
email_val = email.value;
confirm_email_val = confirm_email.value;
console.log(email_val);
console.log(confirm_email_val);
if (email_val !== confirm_email_val) {
alert_box.style.display = 'flex';
event.preventDefault()
}
});
i know camel case is prefered for javascript and Java but I've done more work with python and camel case on variables looks icky to me.
u/MK_Ultra_LSWA — 2 days ago