-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
129 lines (114 loc) · 4.28 KB
/
script.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
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
document.getElementById('player2').style.display = 'flex';
let isTeam = false;
document.getElementById('game').value = 'team';
class Player {
constructor(name, branch, yearOfStudy, section, rollNo, phoneNo, email) {
this.name = name;
this.branch = branch;
this.yearOfStudy = yearOfStudy;
this.section = section;
this.rollNo = rollNo;
this.phoneNo = phoneNo;
this.email = email;
}
}
document.getElementById('game').addEventListener('change', function () {
if (this.value == 'team') {
document.getElementById('player2').style.display = 'flex';
isTeam = true;
} else {
document.getElementById('player2').style.display = 'none';
isTeam = false;
}
});
document.getElementById('submit').addEventListener('click', function () {
submit();
});
console.log(JSON.stringify([new Player('n', 'b', '1', 's', 'r', 'p', 'e')]));
function submit() {
let player1 = new Player(
document.getElementById('name1').value,
document.getElementById('branch1').value,
document.getElementById('year1').value,
document.getElementById('section1').value,
document.getElementById('htno1').value,
document.getElementById('phoneno1').value,
document.getElementById('email1').value
);
let player2 = isTeam
? new Player(
document.getElementById('name2').value,
document.getElementById('branch2').value,
document.getElementById('year2').value,
document.getElementById('section2').value,
document.getElementById('htno2').value,
document.getElementById('phoneno2').value,
document.getElementById('email2').value
)
: null;
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://csi-mrits.tech/api/v1/user/signup');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.status);
console.log(xhr.responseText);
document.getElementById('teamNumber').innerText =
'Team number: ' + JSON.parse(xhr.responseText).msg.teamNo;
document.getElementById('password').innerText =
'Password: ' + JSON.parse(xhr.responseText).password;
}
};
let data =
isTeam && player2
? JSON.stringify([player1, player2])
: JSON.stringify([player1]);
let jsondata = `{"players":${data}}`;
xhr.send(jsondata);
console.log('sent');
document.getElementById('name1').value = '';
document.getElementById('branch1').value = '';
document.getElementById('year1').value = '';
document.getElementById('section1').value = 'A';
document.getElementById('htno1').value = '';
document.getElementById('phoneno1').value = '';
document.getElementById('email1').value = '';
document.getElementById('name2').value = '';
document.getElementById('branch2').value = '';
document.getElementById('year2').value = '';
document.getElementById('section2').value = 'A';
document.getElementById('htno2').value = '';
document.getElementById('phoneno2').value = '';
document.getElementById('email2').value = '';
}
// function generatePlayerField(n) {
// // create a textbox named "name" with id "name1"
// var name = document.createElement("input");
// name.setAttribute("type", "text");
// name.setAttribute("name", "name");
// name.setAttribute("id", `name${n}`);
// name.setAttribute("placeholder", "Name");
// //create a select named "branch" with values "CSE", "CS", "DS", "IT, "ECE", "IOT", "AIML", "Networks" in alphabetic order
// var branch = document.createElement("select");
// branch.setAttribute("name", "branch");
// branch.setAttribute("id", `branch${n}`);
// var options = ["CSE", "CS", "DS", "IT", "ECE", "IOT", "AIML", "Networks"];
// for (var i = 0; i < options.length; i++) {
// var opt = document.createElement("option");
// opt.setAttribute("value", options[i]);
// opt.innerHTML = options[i];
// branch.appendChild(opt);
// }
// // add select with options 1 2 3 4 named "year" with id `year${n}`
// var year = document.createElement("select");
// year.setAttribute("name", "year");
// year.setAttribute("id", `year${n}`);
// var options = [1, 2, 3, 4];
// for (var i = 0; i < options.length; i++) {
// var opt = document.createElement("option");
// opt.setAttribute("value", options[i]);
// opt.innerHTML = options[i];
// year.appendChild(opt);
// }
// //add select named
// }