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.

有帮助吗?

解决方案

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';
})
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top