-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (55 loc) · 1.99 KB
/
Copy pathscript.js
File metadata and controls
63 lines (55 loc) · 1.99 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
/* Define Global Variables */
var alertMessage = "Hi, please make sure to:\n";
var missingFields=[];
var fieldMap = {
'student':"select a Student from the drop-down list",
'course':"select a course in the drop-down list",
'grade':"input a valid Grade form 0 to 100"
}
var student = "";
var course = "";
var grade = "";
function formFieldsFull() {
/* I check if any field is empty, and if it is I save it in
the missingField array*/
if (student === "") {
missingFields.push("student");
}
if (course === "") {
missingFields.push("course");
}
if (grade === "" || parseInt(grade) < 0 || parseInt(grade) > 100) {
missingFields.push("grade");
}
//If the array is empty, then everything is ok, so I return ture
if (missingFields.length === 0) {
//console.log("The fields are full - true");
return true
} else {
return false
}
}
function checkFields() {
student = document.getElementById("student").value;
course = document.getElementById("course").value;
grade = document.getElementById("grade").value;
//console.log("The student is " + student)
//console.log("The course is " + course)
//console.log("The grade is " + grade)
var isFull = formFieldsFull() // I need to call it to get the missingFields
// array before the conditional.
if (isFull) {
return true;
} else {
//console.log("I AM IN THE ALERT - FIELDS EMPTY");
//console.log("THE MISSINGFIELDS ARE: " + missingFields)
while (missingFields.length > 0) {
var value = missingFields.shift() //Removes first element similar to pop()
alertMessage += "*" + fieldMap[value] + "\n";
//console.log(value + " is the value and " + fieldMap[value] + " is the message")
}
alert(alertMessage);
alertMessage = "Hi, please make sure to:\n"; //Reset message in case the submit button is hit again.
return false;
}
}