Question

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.

Was it helpful?

Solution

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';
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top