-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormSubmissionExample01.htm
executable file
·49 lines (43 loc) · 1.9 KB
/
FormSubmissionExample01.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html>
<head>
<title>Form Submission Example</title>
<script type="text/javascript" src="EventUtil.js"></script>
</head>
<body>
<form method="post" action="javascript:alert('Form submitted!')" id="myForm">
<p>This button will submit the form. If the form is submitted, an alert will be displayed.</p>
<input type="submit" value="Submit Form">
</form>
<p>This button determines if the form can be submitted.</p>
<input type="button" value="Block submission" id="myBtn">
<p>This button always submits the form.</p>
<input type="button" value="Force Submit Form" id="myForceBtn">
<script type="text/javascript">
(function(){
function handleSubmitEvent(event){
event = EventUtil.getEvent(event);
EventUtil.preventDefault(event);
}
var btn = document.getElementById("myBtn");
EventUtil.addHandler(btn, "click", function(event){
event = EventUtil.getEvent(event);
var target = EventUtil.getTarget(event);
var form = document.getElementById("myForm");
if (target.value == "Block submission"){
EventUtil.addHandler(form, "submit", handleSubmitEvent);
target.value = "Allow submission";
} else {
EventUtil.removeHandler(form, "submit", handleSubmitEvent);
target.value = "Block submission";
}
});
var forceBtn = document.getElementById("myForceBtn");
EventUtil.addHandler(forceBtn, "click", function(event){
var form = document.getElementById("myForm");
form.submit();
});
})();
</script>
</body>
</html>