-
Notifications
You must be signed in to change notification settings - Fork 1
/
myWork.html
executable file
·160 lines (158 loc) · 5.45 KB
/
myWork.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Edit Forms</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="JQuery.js"></script>
<script src="jquery-ui.js"></script>
<script>
$(document).ready(function(){
$.getJSON("formRetrieve.php", function(data) {
$( '#user-name' ).text(data[0].class);
console.log(data);
var x = data.length;
var currentForm;
var questions;
var display;
var answer;
var correct;
var attempts = 0;
var array = [];
var sendObj = {};
for(i=0;i<x;i++){
$('#titleList').append('<div class="title select" data-index="'+data[i].formID+'">'+data[i].title+'</div>');
}
$('.title').click(function(){
var q = $(this).attr("data-index");
var title = $(this).text()
sendObj.title = title;
// console.log(title);
for(j=0;j<x;j++){
if(data[j].formID == q){
currentForm=data[j];
questions = JSON.parse(currentForm.questions);
totalQ = questions.length;
console.log(questions);
}
}
$('#titleList').remove();
$('#task').show();
$('#go').click(function(){
$('#go').remove();
$('#answer-form').show().focus();
showSum();
});
function showSum(){
if (questions.length > 0) {
attempts = 0;
currentQ = questions.shift();
// console.log(currentQ.question);
display = currentQ.question;
answer = currentQ.answer;
console.log(answer);
$('#here').text(display);
$('#guessInput').focus();
} else {
console.log("finished");
finish();
}
}
$('#checkAns').submit(function( event ){
event.preventDefault();
attempts++;
console.log(attempts);
b = $('#guessInput').val();
if(b === answer){
console.log("correct!")
$('#guessInput').val("");
$('#answer-form').css("border", "10px solid green");
currentQ.correct=true;
currentQ.attempts = attempts;
delete currentQ.question;
delete currentQ.answer;
array.push(currentQ);
console.log(attempts);
console.log(currentQ);
showSum();
} else {
$('#guessInput').val("");
$('#answer-form').css("border", "10px solid red");
$('#seeAns').show();
}
$('#seeAns').off().on('click',function(){
$('#seeErr').show();
$('#seeAns').hide();
$('#guessInput').val("").hide();
$('#accuracy').text("Correct answer: " + display + "-------->" + answer).show();
currentQ.attempts = attempts;
currentQ.correct=false;
delete currentQ.question;
delete currentQ.answer;
array.push(currentQ);
console.log(currentQ);
});
});
$('#seeErr').click(function(e){
event.preventDefault();
$('#answer-form').css('border', '2px black solid');
$('#seeErr').hide();
$('#accuracy').text('');
$('#guessInput').show().focus();
showSum();
})
function finish(){
$('#guessInput').hide();
$('#here').text("Work complete!");
sendObj.array = array;
var pkg = JSON.stringify(sendObj);
console.log(pkg);
$.post('myWorkProcess.php', pkg, function(data){
console.log(data);
//alert("Message sent");
});
}
/* See answer function
$('#seeErr').show();
$('#guessInput').val("").hide();
correct = 0;
$('#accuracy').text("Correct answer: " + display + "-------->" + answer).show();
*/
});
}).fail(function(data) {
$("#login-section").load("teacher-login.html");
});
});
</script>
</head>
<body>
<p id='user-name' style="font-size:18px"></p>
<div>
<div id="titleList">
</div>
</div>
<div id="task" style="display:none">
<div>
<p id="user-name"></p>
<p id="level"></p>
</div>
<button id="go" style="height:50px;width:100px;margin:50px">GO!</button>
<div id="answer-form" style="border:2px black solid; padding: 10px;display:none">
<form id="checkAns" action="no-exist.php">
<div class="input-group">
<p id="here" style="color:black; font-size:20px"></p>
</div>
<div class="input-group">
<input type="text" id="guessInput" style="width:300px; font-family:Arial;font-size:24px" autocomplete="off" class="form-control"/>
</div>
</form>
<button id="seeErr" style="display:none">Okay</button>
<button id="seeAns" style="display:none">See Answer</button>
</div>
<div><h1 style="display:none" id="accuracy">Correct answer:</h1></div>
<div style="display:none" id="time"></div>
<a id="replay" style="display:none" href = "addsub.html">REPLAY</a>
<a id="home" href = "index.html">HOME</a>
</div>
</body>
</html>