-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequiredFieldExample01.htm
executable file
·33 lines (32 loc) · 1.41 KB
/
RequiredFieldExample01.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html>
<head>
<title>Required Field Example</title>
<script type="text/javascript" src="EventUtil.js"></script>
</head>
<body>
<p>Try submitting the following form without filling in a value for the textbox. This only works in HTML5-compliant browsers.</p>
<script>
(function(){
var message = "Your browser does not support required form fields.";
if ("required" in document.createElement("input")){
message = "Your browser supports required form fields!";
}
document.write("<p>" + message + "</p>");
})();
</script>
<form method="post" action="javascript:alert('Form submitted!')" id="myForm">
<label for="username">Username:</label> <input type="text" name="username" id="username" required>
<input type="submit" value="Submit Form"><br>
<input type="button" value="Check Validity" id="btnCheck"><input type="button" value="Will Validate?" id="btnWill">
</form>
<script>
EventUtil.addHandler(document.getElementById("btnCheck"), "click", function(event){
alert(document.forms[0].elements[0].checkValidity());
});
EventUtil.addHandler(document.getElementById("btnWill"), "click", function(event){
alert(document.forms[0].elements[0].willValidate);
});
</script>
</body>
</html>