-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlastPage.js
82 lines (67 loc) · 1.93 KB
/
lastPage.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
79
80
81
82
var lastPage_submitButton = false;
var radioArr = [];
var expiryDays = 5;
function submitData(){
var allChecked = radioButtonChecked();
if(allChecked){
storeDataOnServer();
}else{
return false;
}
}
function radioButtonChecked(){
var allchecked = false;
var radioGroups = [];
radioGroups[0] = document.getElementsByName("1");
radioGroups[1] = document.getElementsByName("2");
radioGroups[2] = document.getElementsByName("3");
radioGroups[3] = document.getElementsByName("4");
radioGroups[4] = document.getElementsByName("5");
radioGroups[5] = document.getElementsByName("6");
for (var i = 0; i < radioGroups.length; i++) {
if(!radioGroupCheck(radioGroups[i])){
alert("Please select a value for question " + (i + 1) + ".");
return false;
}
};
return true;
}
// this function checks if any button in a particular radio groupd is checked.
function radioGroupCheck(radioGroup){
var checked = false;
var index = null;
for (var i = 0; i < radioGroup.length; i++) {
if(checked = radioGroup[i].checked){
index = i;
setCookie(radioGroup[i].name+"radioQuestion", radioGroup[i].value, expiryDays);
radioArr.push({"question": radioGroup[i].name, "answer":radioGroup[i].value});
break;
}
}
return checked;
}
function storeDataOnServer(){
//getUser name
var givenName = getCookie("givenName");
//get all data from array
for (var i = 0; i < radioArr.length; i++) {
radioArr[i]
};
lastPage_submitButton = true;
//document.forms["questions"].submit();
//store it on the php admin database server
}
window.onbeforeunload = function (e) {
if(lastPage_submitButton == true){
e.preventDefault();
return;
}
var e = e || window.event;
var msg = "if you go back you will invalidate your participation in this experiment";
// For IE and Firefox
if (e) {
e.returnValue = msg;
}
// For Safari / chrome
return msg;
};