-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
46 lines (40 loc) · 1.42 KB
/
index.html
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
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="observer.js"></script>
<script type="text/javascript">
(function($){
var text_field_has_value = function(el,evt){
if(el.val().length == 0){
el.css({border:"2px solid red"});
evt.preventDefault();
}
};
var last_valid = function(opts){
text_field_has_value(opts.sender.find("input[type=text]#last_name"),opts.event);
}
var first_valid = function(opts){
text_field_has_value(opts.sender.find("input[type=text]#first_name"),opts.event);
}
var not_empty = function(opts){
if(opts.data.length == 0) {
opts.sender.css({border:"2px solid red"});
opts.event.preventDefault();
}
}
$.listen_for({message:"textFieldBlur", delegate:not_empty, scope:"#first_name"});
$.listen_for({message:"submitInvoked", delegates:[first_valid, last_valid]});
})(jQuery);
</script>
</head>
<body>
<form id="my_form" action="#" method="GET">
<label for="first_name">First:</label>
<input type="text" name="first_name" id="first_name"><br>
<label for="last_name">Last:</label>
<input type="text" name="last_name" id="last_name"><br>
<input type="submit" value="update">
</form>
<div id="msg"></div>
</body>
</html>