-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject1.html
488 lines (364 loc) · 13.6 KB
/
project1.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Project 1</title>
<link rel="stylesheet" href="styles.css">
<script>
//browser detection if not modern send them to firefox download page
if( !document.getElementById){
//send them away
window.location="https://www.mozilla.org/en-US/firefox/new/";
}
var ie7 = false;
function $(id){
return document.getElementById(id);
}
</script>
<!--[if lt IE 8]>
<script>
var ie7 = true;
</script>
<![endif]-->
<script src="data.js"></script>
<script src="cookies.js"></script>
<script>
var selectedTeam;
var opacity = 0;
function animation(dom){
//must mean that the resultimage was passed in
if (dom.nodeName == "IMG"){
if (isNaN((dom.style.opacity))){
dom.style.opacity = 0;
}
if(dom.style.opacity < 1.0){
dom.style.opacity = opacity;
opacity += 0.02;
setTimeout(function(){animation(dom);},30);
}
}
else{
//get parent node of the select, which is the divContainer, then go to the next sibling
var hold = dom.parentNode.nextSibling;
//if it doesn't already have a marginLeft give it one
if(isNaN(parseInt(hold.style.marginLeft))){
hold.style.marginLeft = "5px";
}
if(hold == document.getElementById("container").childNodes[2]){
if(parseInt(hold.style.marginLeft) < 100){
hold.style.marginLeft = parseInt(hold.style.marginLeft) + 3 + 'px';
setTimeout(function(){animation(dom);},30);
}
}
if(hold == document.getElementById("container").childNodes[3]){
if(parseInt(hold.style.marginLeft) < 200){
hold.style.marginLeft = parseInt(hold.style.marginLeft) + 3 + 'px';
setTimeout(function(){animation(dom);},30);
}
}
if(hold == document.getElementById("container").childNodes[4]){
if(parseInt(hold.style.marginLeft) < 300){
hold.style.marginLeft = parseInt(hold.style.marginLeft) + 5 + 'px';
setTimeout(function(){animation(dom);},30);
}
}
}
}
function validate(){
var errMsg= "";
var start="Please complete the following fields: " ;
//if first name doesn't have a value
if (!$("first-name").value){
errMsg += "First Name, ";
$("first-name").style.border = "solid red";
}
//first name has a value
else{
$("first-name").style.border = "2px inset #EBE9ED";
if(localStorage){
if(!localStorage.getItem('firstname')){
localStorage.setItem('firstname', $('first-name').value);
}
}
else{
if(GetCookie('firstname') == null){
//store the name
SetCookie('firstname',$('first-name').value);
}
}
}
//if last name doesn't have a value
if (!$("last-name").value){
errMsg += "Last Name, ";
$("last-name").style.border = "solid red";
}
//last name has a value
else{
$("last-name").style.border = "2px inset #EBE9ED";
if(localStorage){
if(!localStorage.getItem('lastname')){
localStorage.setItem('lastname', $('last-name').value);
}
}
else{
if(GetCookie('lastname') == null){
//store the name
SetCookie('lastname',$('last-name').value);
}
}
}
// Age field, make sure there is input and it is a number
if (!$("age").value){
errMsg += "Age, ";
$("age").style.border = "solid red";
}
else{
$("age").style.border = "2px inset #EBE9ED";
if(localStorage){
if(!localStorage.getItem('age')){
localStorage.setItem('age', $('age').value);
}
}
else{
if(GetCookie('age') == null){
//store the name
SetCookie('age',$('age').value);
}
}
}
// <!-- State field, is there not a value? -->
if (!$("state").value){
errMsg += "State ";
$("state").style.border = "solid red";
}
else{
$("state").style.border = "2px inset #EBE9ED";
if(localStorage){
if(!localStorage.getItem('state')){
localStorage.setItem('state', $('state').value);
}
}
else{
if(GetCookie('state') == null){
//store the name
SetCookie('state',$('state').value);
}
}
}
if(errMsg != ""){
var feedbackDiv = $("feedback-div");
var p = document.createElement('p');
p.setAttribute('class','feedback');
var text = document.createTextNode(start + errMsg);
p.appendChild(text);
feedbackDiv.appendChild(p);
//get rid of the previous feedback text node
if(document.getElementById("feedback-div").childNodes.length > 1){
feedbackDiv.removeChild(document.getElementById("feedback-div").childNodes[0]);
}
feedbackDiv.style.display = "block";
return false;
// <!-- prevents form from submitting -->
}
}
</script>
<script type="text/javascript">
//<![CDATA[
//some possible methods/props you will use! (know them!)
//createElement, setAttribute, appendChild, replaceChild, createTextNode, childNodes[], firstChild,
//nodeType, nodeName, nodeValue, getElementById, getElementsByTagName
function construct(dom){
//if the container div doesn't have any child elements
if(typeof(dom)=="string"){
var hold = data[dom];
}
else{
// dom.value is the select option that was selected
var hold = data[dom.value];
//destruction code
//while the parent element of the current element
//is not the last child of the parent node
while(dom.parentNode != dom.parentNode.parentNode.lastChild){
dom.parentNode.parentNode.removeChild(dom.parentNode.parentNode.lastChild);
if (document.getElementById("resultImg")){
document.getElementById("result").removeChild(document.getElementById("resultImg"));
}
}
}
if (hold!=undefined){
var length = hold.length;
//create the div container
var div = document.createElement('div');
div.setAttribute('class', 'divContainer');
$('container').appendChild(div);
//create div tag to hold the image tag
var divImg = document.createElement('div');
div.appendChild(divImg);
//create the image tag
var img = document.createElement('img');
img.setAttribute('class','img');
img.src = hold[0];
divImg.appendChild(img);
//create the select
var sel = document.createElement('select');
sel.setAttribute('name', 'selectmenu');
if (ie7){
sel.setAttribute('onchange', function(){construct(this);animation(this);});
}
else{
sel.setAttribute('onchange', 'construct(this);animation(this)');
}
//create the options for the select menu
for (var i = 1; i < length; i++){
var opt = document.createElement('option');
if(i == 1){
opt.setAttribute('disabled','disabled');
opt.setAttribute('selected','selected');
}
opt.setAttribute('value', hold[i]);
opt.appendChild(document.createTextNode(hold[i]));
sel.appendChild(opt); //append the option to the select menu
}
div.appendChild(sel);
}
else { //no more data, create the form
selectedTeam = dom.value;
//create the image tag
var resImg = document.createElement('img');
resImg.setAttribute('id','resultImg');
resImg.src = res[selectedTeam];
//reset opacity variable back to 0
opacity = 0;
animation(resImg);
var divForm = document.createElement('div');
divForm.setAttribute('class', 'divContainer');
var feedbackDiv = document.createElement('div');
feedbackDiv.setAttribute('id','feedback-div');
divForm.appendChild(feedbackDiv);
$('container').appendChild(divForm);
var form = document.createElement('form');
form.setAttribute('method','post');
form.setAttribute('id','contact-form');
form.setAttribute('action','project1.html');
if (ie7){
form.setAttribute('onsubmit', function(){return validate();});
}
else{
form.setAttribute('onsubmit','return validate();');
}
divForm.appendChild(form);
var p = document.createElement('p');
var label = document.createElement('label');
var text = document.createTextNode("First Name");
label.appendChild(text);
label.setAttribute('for','first-name');
var firstName = document.createElement('input');
firstName.setAttribute('name','first-name');
firstName.setAttribute('id','first-name');
firstName.setAttribute('size','16');
firstName.setAttribute('maxlength','16');
label.appendChild(firstName);
p.appendChild(label);
//if has localStorage
if(localStorage){
//if the the firstname value is stored in localStorage
if(localStorage.getItem('firstname')){
firstName.value=localStorage.getItem('firstname');
}
}
else{
if(GetCookie('firstname') != null){
firstName.value = GetCookie('firstname');
}
}
var label = document.createElement('label');
var text = document.createTextNode("Last Name");
label.appendChild(text);
label.setAttribute('for','last-name');
var lastName = document.createElement('input');
lastName.setAttribute('name','last-name');
lastName.setAttribute('id','last-name');
lastName.setAttribute('size','16');
lastName.setAttribute('maxlength','16');
label.appendChild(lastName);
p.appendChild(label);
form.appendChild(p);
if(localStorage){
//if the the firstname value is stored in localStorage
if(localStorage.getItem('lastname')){
lastName.value=localStorage.getItem('lastname');
}
}
else{
if(GetCookie('lastname') != null){
lastName.value = GetCookie('lastname');
}
}
var p = document.createElement('p');
var label = document.createElement('label');
var text = document.createTextNode("Age");
label.appendChild(text);
label.setAttribute('for','age');
var age = document.createElement('input');
age.setAttribute('name','age');
age.setAttribute('id','age')
age.setAttribute('size','3');
age.setAttribute('maxlength','3');
label.appendChild(age);
p.appendChild(label);
if(localStorage){
//if the the firstname value is stored in localStorage
if(localStorage.getItem('age')){
age.value=localStorage.getItem('age');
}
}
else{
if(GetCookie('age') != null){
age.value = GetCookie('age');
}
}
var label = document.createElement('label');
var text = document.createTextNode("State");
label.appendChild(text);
label.setAttribute('for','state');
label.setAttribute('id','labelState');
var state = document.createElement('input');
state.setAttribute('name','state');
state.setAttribute('id','state');
state.setAttribute('size','16');
state.setAttribute('maxlength','16');
if(localStorage){
//if the the firstname value is stored in localStorage
if(localStorage.getItem('state')){
state.value=localStorage.getItem('state');
}
}
else{
if(GetCookie('state') != null){
state.value = GetCookie('state');
}
}
label.appendChild(state);
p.appendChild(label);
form.appendChild(p);
var p = document.createElement('p');
var submit = document.createElement('input');
submit.setAttribute('type','submit');
submit.setAttribute('value','submit');
submit.setAttribute('id','submit');
p.appendChild(submit);
form.appendChild(p);
//put large team image on page
document.getElementById("result").appendChild(resImg);
}
}
//]]>
</script>
</head>
<body onload="construct('init')">
<div id = "result">
</div>
<div id = "container">
</div>
</body>
</html>