Last active
December 17, 2018 17:40
-
-
Save Opus1no2/c6f8579eda0351967fed3a5394569977 to your computer and use it in GitHub Desktop.
form submission
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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