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

javascript stop the form from reloading

Use <button type="button"> to override default submission behavior
Use event.preventDefault() in the onSubmit event to prevent form submission
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to check how many strings are in a sentence javascript 
Javascript :: number to word js 
Javascript :: google maps places autocomplete api 
Javascript :: jquery find div with data attribute value 
Javascript :: detect a click outside an element javascript 
Javascript :: n javascript 
Javascript :: js capitalize first letter 
Javascript :: sublime node 
Javascript :: javascript get month string 
Javascript :: ajax request in javascript 
Javascript :: convert array to number js 
Javascript :: js Date(date).toLocaleString() MINUUTES 
Javascript :: pass id to reactjs routes 
Javascript :: how to hide a input and label jquery 
Javascript :: event loop 
Javascript :: nodejs javascript heap out of memory 
Javascript :: javascript sort numbers descending 
Javascript :: javascript sort multidimensional array 
Javascript :: postasync json C# 
Javascript :: ion input ios keyboard over 
Javascript :: react native cross out letter 
Javascript :: jshint esversion: 6 
Javascript :: jquery force page to reload on viewport resize 
Javascript :: statement and expression in js 
Javascript :: javascript immediately invoked function expression 
Javascript :: how to loop an object in javascript 
Javascript :: javascript round to 2 decimals 
Javascript :: how to open component as a dialog in angular 
Javascript :: if classlist contains js 
Javascript :: react fragment 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =