-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.form.html
More file actions
80 lines (63 loc) · 1.79 KB
/
jquery.form.html
File metadata and controls
80 lines (63 loc) · 1.79 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
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Form - jQuery plugin for in-line editing (save, edit, and cancel)</title>
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="jquery.form.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="jquery.form.css">
</head>
<body>
<form>
<p>
<label for="text">First name:</a>
<input type="text" id="text">
</p>
<p>
<label for="select">Sex:</label>
<select id="select">
<option>Male</option>
<option>Female</option>
<option>Meh</option>
</select>
</p>
<p>
<label for="checkbox">In a relationship:</label>
<input type="checkbox" id="checkbox" value="Yes">
</p>
<input type="button" id="save" value="Save">
<input type="button" id="edit" value="Edit">
<a href="#" id="cancel">Cancel</a>
</form>
<script>
$(function() {
// Cancel the submition of the form
$("form").submit(function() { return false; });
// Hide the edit and cancel links
$("#edit, #cancel").hide();
// Bind the save button
$("#save").click(function() {
$("input[type=text], select, input[type=checkbox]").save();
$("#save, #cancel").hide();
$("#edit").show().focus();
});
// Bind the edit button
$("#edit").click(function() {
$("input[type=text], select, input[type=checkbox]").edit();
$("#save, #cancel").show();
$("#edit").hide();
$("#text").select().focus();
});
// Bind the cancel button
$("#cancel").click(function(event) {
event.preventDefault();
$("input[type=text], select, input[type=checkbox]").cancel();
$("#save, #cancel").hide();
$("#edit").show().focus();
});
// Focus on the first element
$("#text").select().focus();
})
</script>
</body>
</html>