forked from jmanosu/CS_340_Final_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
championHandler.js
executable file
·76 lines (67 loc) · 2.21 KB
/
championHandler.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
function RerollStats(){
var level = document.getElementById('level').value;
var power = 5 * level + Math.floor(Math.random()*5);
var intelligence = 5 * level + Math.floor(Math.random()*5);
var endurance = 5 * level + Math.floor(Math.random()*5);
document.getElementById('power').value = power;
document.getElementById('intelligence').value = intelligence;
document.getElementById('endurance').value = endurance;
CalcCredits();
}
function CalcCredits(){
var level = document.getElementById('level').value;
var cost = Number(document.getElementById('power').value);
cost += Number(document.getElementById('intelligence').value);
cost += Number(document.getElementById('endurance').value);
cost = Math.floor(cost / 10);
document.getElementById('cost').innerHTML = "Cost: " + cost;
document.getElementById('cost').value = cost;
}
function isBlank(inputField){
if(inputField.type=="checkbox"){
if(inputField.checked)
return false;
return true;
}
if (inputField.value==""){
return true;
}
return false;
}
//function to highlight an error through colour by adding css attributes tot he div passed in
function makeRed(inputDiv){
inputDiv.style.backgroundColor="#AA0000";
//inputDiv.parentNode.style.backgroundColor="#AA0000";
inputDiv.parentNode.style.color="#FFFFFF";
}
//remove all error styles from the div passed in
function makeClean(inputDiv){
inputDiv.parentNode.style.color="#000000";
}
window.onload = function(){
RerollStats();
var myForm = document.getElementById("addCham");
//all inputs with the class required are looped through
var requiredInputs = document.querySelectorAll(".required");
for (var i=0; i < requiredInputs.length; i++){
requiredInputs[i].onfocus = function(){
this.style.backgroundColor = "#EEEE00";
}
}
//on submitting the form, "empty" checks are performed on required inputs.
myForm.onsubmit = function(e){
var requiredInputs = document.querySelectorAll(".required");
for (var i=0; i < requiredInputs.length; i++){
if( isBlank(requiredInputs[i]) ){
e.preventDefault();
makeRed(requiredInputs[i]);
}
else{
makeClean(requiredInputs[i]);
}
}
if ( !checkPswds() ) {
e.preventDefault();
}
}
}