Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to stop form from reloading page

 <form id="form">
            <input type="text" name="name" id="user-name" placeholder="Enter your name">
            <input type="email" name="email id="user-email" placeholder="Enter your email">
            <button id="submit" type="submit">Submit</button>
        </form>
<script>
var form = document.getElementById("form");
form.addEventListener("submit",(e)=>{
    e.preventDefault();
    //This will prevent the form from reloading
    //Because you are preventing the default
})
</script>
Comment

why does my page reloads on form submission

//jquery method //
//preventDefault() prevents the submit button
//from performing its default task like page reload  
  $('#form').submit(function (e) {
      e.preventDefault();
  });
Comment

Stop form refreshing page on submit

<form onsubmit="return false">
Comment

PREVIOUS NEXT
Code Example
Javascript :: material ui textfield error 
Javascript :: angular call function every x seconds 
Javascript :: react check if in mobile 
Javascript :: react date picker disable past dates 
Javascript :: how to get value from input field in javascript 
Javascript :: how to check if a string is alphabetic in javascript 
Javascript :: discord js convert timestamp to date 
Javascript :: js dynamicly add script 
Javascript :: splidejs pause 
Javascript :: remove all white space from text javascript 
Javascript :: javascript reduce array of objects 
Javascript :: react hooks delete item from array 
Javascript :: angular generate module with rooting 
Javascript :: javascript traverse 
Javascript :: javascript string unique characters 
Javascript :: how to append rows in table using jquery each function 
Javascript :: count number of divs inside a div jquery 
Javascript :: code Execution time in nodejs 
Javascript :: getvalue data from datetimepicker 
Javascript :: comment in react 
Javascript :: ant design not working in react js 
Javascript :: test if property exists javascript 
Javascript :: socket io client 
Javascript :: speedtest-net node.js 
Javascript :: safeareaview react native 
Javascript :: Type io.invertase.firebase.BuildConfig is defined multiple times 
Javascript :: javascript newline in alert 
Javascript :: javascript parse a json string 
Javascript :: postcss.config.js 
Javascript :: check if message mentions users discord js 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =