Form submit if valid
Form submit if valid
by vieckys
HTML
<form action="/" id="form">
<input type="text" id="username" />
<button type="submit">Submit</button>
</form>
<h2 id="result"></h2>
JavaScript
$('#form').submit(function(event){
if ($('#username').val().length < 6) {
// you code if validation failed
event.preventDefault();
$("#result").html('COPY FAILED');
} else {
// you code if validation succeed and form is valid
// it will auto submit form, so no need to register
// submit and click event separatly.
$("#result").html('COPY SUCCESS');
}
});