form submit override with javascript

if you need to run some additional checks on a form before submitting it

HTML

<form id="myform" onsubmit="event.preventDefault(); validate_form();">
	<input type="text" placeholder="My Awesome Form Element">
  	<input type="Submit" value="Submit Me!">
</form>

Javascript

function validate_form()
{
  var valid = false; // check form elements here and then set to true if they are valid
  if(valid == false) { 
    alert("validation failed false");
    returnToPreviousPage();
    return false;
  }

  alert("validations passed");
  return true;
}

// form validation

Other Items in javascript

No Items Found.

Add Comment
Type in a Nick Name here
 
Page Views

This page has been viewed 103 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

âĪðŸ‘Đ‍ðŸ’ŧðŸ•đ

Random Quote
There is no way to happiness. Happiness is the way.
Unknown