Created
January 12, 2019 13:08
-
-
Save mulderu/c392328699e9acae318f3ca954362baf to your computer and use it in GitHub Desktop.
html5 form validation and user message
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> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>HTML5 Form Validation Ex</title> | |
<script src="https://code.jquery.com/jquery-3.1.0.js"></script> | |
</head> | |
<body> | |
<form onsubmit="return false;"> | |
<label for="choose">Would you prefer a banana or a cherry?</label> | |
<input id="choose" name="i_like" required pattern="banana|cherry" > | |
<button>Submitx</button> | |
</form> | |
<script> | |
$(document).ready(myInit); | |
function myInit() { | |
$('#choose').blur(function(e) { | |
setTimeout(function() { | |
$('#choose')[0].setCustomValidity('hello mulder'); | |
$('#choose')[0].reportValidity(); | |
}, 1); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment