Skip to content

Instantly share code, notes, and snippets.

@Opus1no2
Last active December 17, 2018 17:40
Show Gist options
  • Save Opus1no2/c6f8579eda0351967fed3a5394569977 to your computer and use it in GitHub Desktop.
Save Opus1no2/c6f8579eda0351967fed3a5394569977 to your computer and use it in GitHub Desktop.
form submission
<!doctype html>
<html>
<head>
</head>
<body>
<form>
<label>First Name</label>
<input name='first' type='text'>
<label>Last Name</label>
<input name='last' type='text'>
<button type='submit'>Submit Form</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>
$('form').on('submit', (e) => {
e.preventDefault();
const data = $(':input').serializeArray();
data.forEach((input) => {
if (input.value.length > 0) {
$('form').trigger('validated');
} else {
console.log('bad data');
}
});
});
$('form').on('validated', (e) => {
e.preventDefault();
console.log('success')
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment