-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathindex.html
More file actions
68 lines (67 loc) · 1.71 KB
/
index.html
File metadata and controls
68 lines (67 loc) · 1.71 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE HTML>
<html lang="en">
<head> <title>Input Error Notification with aria-live=assertive and aria-invalid using jQuery: WCAG 2</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function(e) {
$('#signup').submit(function() {
$('#errText').html('');
$('input').removeAttr("aria-invalid");
$('label').removeAttr("class");
var eFlag = 0;
if ($('#first').val() === '') {
$('#first').attr("aria-invalid", "true");
$("label[for='first']").addClass('failed');
eFlag++;
}
if ($('#last').val() === '') {
$('#last').attr("aria-invalid", "true");
$("label[for='last']").addClass('failed');
eFlag++;
}
if ($('#email').val() === '') {
$('#email').attr("aria-invalid", "true");
$("label[for='email']").addClass('failed');
eFlag++;
}
if (eFlag > 0) {
$('#errText').html("Please complete all required fields (" + eFlag + ") and retry").focus();
}
return false;
});
});
</script>
<style>
body{
background:#fff;
color:#000;
font:100% / 1.5 sans-serif;
}
label.failed {
border: red thin solid;
}
</style>
</head>
<body>
<h2 tabindex="-1" id="errText" aria-live="assertive"></h2>
<form name="signup" id="signup" method="post" action="#">
<p>
<label for="first">First Name (required)</label><br>
<input type="text" name="first" id="first">
</p>
<p>
<label for="last">Last Name (required)</label><br>
<input type="text" name="last" id="last">
</p>
<p>
<label for="email">Email (required)</label><br>
<input type="text" name="email" id="email">
</p>
<p>
<input type="submit" name="button" id="button" value="Submit">
</p>
</form>
</body>
</html>