-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch18_exe2.html
40 lines (38 loc) · 958 Bytes
/
ch18_exe2.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Chapter 18:Question 2</title>
</head>
<body>
<form name="form1" action="">
<input type="text" id="text1" name="text1" />
<br />
CheckBox 1<input type="checkbox" id="checkbox2" name="checkbox2" />
<br />
CheckBox 1<input type="checkbox" id="checkbox1" name="checkbox1" />
<br />
<input type="text" id="text2" name="text2" />
<p>
<input type="submit" value="Submit" id="submit1" name="submit1" />
</p>
</form>
<script>
function checkForm(e) {
var elementCount = 0;
var theForm = document.form1;
while(elementCount < theForm.length){
if (theForm.elements[elementCount].type == "text") {
if (theForm.elements[elementCount].value == ""){
alert("Please complete all form elements");
theForm.elements[elementCount].focus();
e.prentDefault();
break;
}
}
elementCount++;
}
}
document.form1.addEventListener("submit", checkForm);
</script>
</body>
</html>