how to prevent the form from getting automatically submitted javascript 1

how to prevent the form from getting automatically submitted javascript

//add event.preventDefault() example,

function clickHandler(event){
	alert("Hey you clicked the submit button");
	event.preventDefault();
}

//this will prevent the page from getting automatically refreshed after 
//the submit button is hit.

Here is what the above code is Doing:
1. We are selecting the submit button using the id attribute.
2. We are adding an event listener to the submit button.
3. We are passing the event object to the clickHandler function.
4. We are preventing the default behavior of the submit button.

Similar Posts