Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  169] [ 5]  / answers: 1 / hits: 139589  / 11 Years ago, fri, january 24, 2014, 12:00:00

This is what I have and it's not working.


document.getElementById('form1').addEventListener('submit', function(){
document.getElementById('donate').style.display = 'none';
document.getElementById('topMessage').style.display = 'none';
});

The JavaScript console shows this error:



Uncaught TypeError: Cannot set property 'onclick' of undefined



Any suggestion is much appreciated.


More From » dom-events

 Answers
39

Okay, I figured it out. All I need the preventDefault(); So, here's the solution.



document.getElementById('form1').addEventListener('submit', function(evt){
evt.preventDefault();
document.getElementById('donate').style.display = 'none';
document.getElementById('topMessage').style.display = 'none';
})

[#72961] Thursday, January 23, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micah

Total Points: 295
Total Questions: 104
Total Answers: 92

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
;