-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiz.js
78 lines (69 loc) · 2.4 KB
/
quiz.js
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
var cont = true;
function loadData()
{
var xhttp = new XMLHttpRequest();
var cost = document.getElementById("form1");
var location = document.getElementById("form2");
var external = document.getElementById("form3");
var job = document.getElementById("form6");
var race = document.getElementsByName("race");
var disorders = document.getElementsByName("disorders");
var income = document.getElementsByName("income");
var error = document.getElementById("error");
sessionStorage.setItem("scholarships", []);
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
sessionStorage.setItem("scholarships", (xhttp.responseText));
console.log(xhttp.responseText);
}
};
sessionStorage.setItem("costAttendance", parseInt(cost.elements[0].value));
validateData("costAttendance");
sessionStorage.setItem("costLiving", parseInt(cost.elements[1].value));
validateData("costLiving");
sessionStorage.setItem("state", (location.elements[0].value));
sessionStorage.setItem("city", (location.elements[1].value));
sessionStorage.setItem("job", (job.elements[0].value));
sessionStorage.setItem("familyContributions", parseInt(external.elements[0].value));
validateData("familyContributions");
sessionStorage.setItem("grants", parseInt(external.elements[1].value));
validateData("grants");
sessionStorage.setItem("other", parseInt(external.elements[2].value));
validateData("other");
for(var i = 0; i < race.length; i++)
{
if(race[i].checked)
{
sessionStorage.setItem("race", race[i].value);
}
}
for(var i = 0; i < disorders.length; i++)
{
if(disorders[i].checked)
{
sessionStorage.setItem("disorders", disorders[i].value);
}
}
for(var i = 0; i < income.length; i++)
{
if(income[i].checked)
{
sessionStorage.setItem("income", disorders[i].value);
}
}
if(cont)
{
window.location.href = "output.html";
}
}
function validateData(id)
{
if(isNaN(sessionStorage.getItem(id)))
{
cont = false;
error.innerText = "invalid value found or field not entered";
} else if(cont) {
cont = true;
error.innerText = "";
}
}