what happens after a form is submitted?

后端 未结 4 1847
故里飘歌
故里飘歌 2021-01-26 00:45

This might be a broad answer to give but i\'l try to shorten it up. What i am trying to do is use a form to get some information from the user and \"validate the form\" using Ja

4条回答
  •  有刺的猬
    2021-01-26 01:10

    You need to use event.preventDefault() to prevent the default action of the form, which is submitting.

    Change

    document.getElementById('submit').addEventListener('click',
     function(e){
     document.querySelector('.feedback-background').style.display='none';
     document.querySelector('.popup').style.display='flex';
    }
    

    To

    document.getElementById('submit').addEventListener('click',
    function(e){
     document.querySelector('.feedback-background').style.display='none';
     document.querySelector('.popup').style.display='flex';
     e.preventDefault();
     }
    

    However, preventing the form from submitting will prevent the data from the form from being sent to the server to be processed and saved in the database. To be able to process data sent to the server, you will need to use some server-side programming language and you will need to set the form's action attribute; Javascript is not sufficient for this task.

提交回复
热议问题