-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
145 lines (138 loc) · 4.08 KB
/
index.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var btns = $(".nav-item")
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function () {
var current = document.getElementsByClassName("active")
current[0].className = current[0].className.replace("nav-link active", "nav-link")
this.children[0].className = "nav-link active"
})
}
$(document).ready(function () {
$(window).scroll(function () {
if ($(this).scrollTop() > 50) {
$('#back-to-top').fadeIn();
} else {
$('#back-to-top').fadeOut();
}
});
// scroll body to 0px on click
$('#back-to-top').click(function () {
$('body,html').animate({
scrollTop: 0
}, 200);
return false;
});
});
var TopOffset = 100;
$('a[data-smooth]').click(function () {
var current = document.getElementsByClassName("active")
console.log(current[0], $(this).children('a'))
const selected = $(this).children('a')
console.log(selected.prevObject[0].className)
current[0].className = current[0].className.replace("nav-link active", "nav-link")
selected.prevObject[0].className = "nav-link active"
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top - TopOffset
}, 200);
return false;
}
}
});
const nameRegex = /^[a-zA-Z ]{3,30}$/;
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
const phoneRegex = /^[0-9]{10}$/;
const branch = ["IT", "CE", "Other", "MECH", "AI&DS", "AI&ML", "EXTC"];
const year = ["1", "2", "3", "4"];
// const arenaIdURL = (name) => {
// return `http://arena.siesgst.ac.in/api/user?username=${name}`
// }
// const headers = {
// 'Accept': 'application/vnd.arena+json;version=1',
// 'Access-Control-Allow-Origin': '*'
// }
function submitForm(event) {
event.preventDefault();
const name = $("[name='name']").val();
const email = $("[name='email']").val();
const phoneNo = $("[name='phoneNo']").val();
const branch = $("[name='branch']").val();
const year = $("[name='year']").val();
const arenaId = $("[name='arenaId']").val();
const collegeName = $("[name='collegename']").val();
const teamName = $("[name='teamName']").val();
const transactionId = $("[name='transactionId']").val();
const name2 = $("[name='name2']").val();
const email2 = $("[name='email2']").val();
const phoneNo2 = $("[name='phoneNo2']").val();
const branch2 = $("[name='branch2']").val();
const year2 = $("[name='year2']").val();
const arenaId2 = $("[name='arenaId2']").val();
const collegeName2 = $("[name='collegename2']").val();
// Validating Data
if (!nameRegex.test(name)) {
alert("Person1 Name is not valid");
return;
}
if (!emailRegex.test(email)) {
alert("Person1 Email is not valid");
return;
}
if (!phoneRegex.test(phoneNo)) {
alert("Person1 Phone Number is not valid");
return;
}
if (!nameRegex.test(name2)) {
alert("Person2 Name is not valid");
return;
}
if (!emailRegex.test(email2)) {
alert("Person2 Email is not valid");
return;
}
if (!phoneRegex.test(phoneNo2)) {
alert("Person2 Phone Number is not valid");
return;
}
if (!branch.includes(branch)) {
alert("Branch is not valid");
return;
}
if (!year.includes(year)) {
alert("Year is not valid");
return;
}
// sending data to server
const URL = 'http://localhost:3000/bug4ever/register';
const data = {
name,
email,
phoneNo,
branch,
year,
arenaId,
collegeName,
teamName,
transactionId,
name2,
email2,
phoneNo2,
branch2,
year2,
arenaId2,
collegeName2
}
// $.ajax({
// url: URL,
// type: 'POST',
// data: data,
// success: function (response) {
// alert("Successfully Registered");
// },
// error: function (error) {
// alert("Error in registering");
// }
// });
}