-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent.js
240 lines (233 loc) · 9.67 KB
/
student.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
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
/*
* Javascript ::
*/
//Password checking
document.getElementById('password').addEventListener("keyup",function(){
var reg = document.getElementById('register_button');
var pass = document.getElementById('password');
var conf_pass = document.getElementById('conf_pass');
var message = document.getElementById("message");
if(pass.value == conf_pass.value){
reg.style.opacity=1;
reg.style.backgroundColor="tomato";
reg.setAttribute('onmouseenter','this.style.backgroundColor="#ff1aff"');
reg.setAttribute('onmouseleave','this.style.backgroundColor="tomato"');
reg.disabled=false;
message.style.color="green";
message.style.display="inline-block";
message.innerHTML='Password Matched';
}
else{
reg.style.backgroundColor="#BFC9CA";
reg.style.opacity=0.5;
reg.removeAttribute('onmouseenter');
reg.removeAttribute('onmouseleave');
reg.disabled=true;
message.innerHTML='Password not Matching';
message.style.color='red';
message.style.display="inline-block";
}
});
document.getElementById('conf_pass').addEventListener("keyup",function(){
var reg = document.getElementById('register_button');
var pass = document.getElementById('password');
var conf_pass = document.getElementById('conf_pass');
var message = document.getElementById("message");
if(pass.value == conf_pass.value){
reg.style.opacity=1;
reg.style.backgroundColor="tomato";
reg.setAttribute('onmouseenter','this.style.backgroundColor="#ff1aff"');
reg.setAttribute('onmouseleave','this.style.backgroundColor="tomato"');
reg.disabled=false;
message.style.color="green";
message.style.display="inline-block";
message.innerHTML='Password Matched';
}
else{
reg.style.backgroundColor="#BFC9CA";
reg.style.opacity=0.5;
reg.removeAttribute('onmouseenter');
reg.removeAttribute('onmouseleave');
reg.disabled=true;
message.innerHTML='Password not Matching';
message.style.color='red';
message.style.display="inline-block";
document.getElementById("message").innerHTML = serialize(document.forms[0]);
}
});
/*
* JQuery ::
*/
function show(x){
$("#register , #home, #login, #profile").hide();
$('#'+x).fadeIn();
}
//age
$("input[name ='DOB']").change(function(){
var dob=new Date($(this).val());
var today= new Date();
var age=today.getFullYear()-dob.getFullYear();
if(today.getMonth() < dob.getMonth() || (today.getMonth()==dob.getMonth() && today.getDate()<dob.getDate()))
age--;
$("input[name ='age']").val(age);
});
$(document).ready(function(){
if(login!="0"){
$("#register , #home, #login, #profile").hide();
$('#login').fadeIn();
$('#message1').text(login).css({'display':'inline-block'});
if(login=="You are logged in,Check Profile"){
//banner
$('#login').find('button').attr('disabled','disabled').css('background-color','grey');
$('.banner').fadeTo('slow', 0, function(){
$(this).css({'background-image':'url(img/std_img/'+regno+'.jpg),url(img/banner.jpg)',
'background-size':'cover',
'background-position-x':'0px',
'background-position':'center',
'background-attachment':'fixed'
});
}).fadeTo('slow', 1)
//titles
$('.title2').fadeTo('slow', 0, function(){
$(this).css({'background-image':'url(img/std_img/'+regno+'.jpg),url(img/banner.jpg)',
'background-size':'cover',
'background-position-x':'0px',
'background-position':'center',
'background-attachment':'fixed'
});
}).fadeTo('slow', 1)
}
}
//Roll no insatalling
$("#register").find("input[name='regno'],select[name='branch']").blur(function(){
x=$("#register").find("input[name='regno']").val();
var selected = $("select[name='branch'] option:selected").val();
x=x/10000;
if(x>999 && selected!="Select Branch"){
if(Math.floor(x)%100<=9) //Special case for year 2001,2002,2003 etc
$("input[name=rollno]").val("0"+Math.floor(x)%100+"/"+selected+"/");
else
$("input[name=rollno]").val(Math.floor(x)%100+"/"+selected+"/");
}
else
$("input[name=rollno]").val(null);
});
//Ajax registration
$("#register").find('form').submit(function(e){
e.preventDefault();
serializedData=$(this).serialize();
var request=$.ajax({
url: "reg.php",
type: "post",
data: serializedData
});
request.done(function (response, textStatus, jqXHR){
$("#message").text(response);
});
request.fail(function (jqXHR, textStatus, errorThrown){
alert("Unable to Handle request please try again later !!");
});
});
$("input[name ='DOB']").change();
$("#age").text($("input[name ='age']").val());
});
//Validation
function Validate(x){
//Block register button
$("#register").find("button[type=submit]").attr("disabled","disabled");
//Registration Number
if($(x).attr('name')=="regno"){
if(!$(x).val())
$("#regnoError").css({'background-color':'red','color':'white'}).text("Please Insert Registration Number !!").slideDown();
else if($(x).val()<10000000)
$("#regnoError").css({'background-color':'red','color':'white'}).text("Registration Number less than 8 digits").slideDown();
else
$("#regnoError").css({'background-color':'#65FF00','color':'green'}).text("Registration Number Ok");
}
//Roll no
else if($(x).attr('name')=="rollno"){
if(!$(x).val())
$("#rollError").css({'background-color':'red','color':'white'}).text("Please complete above details to get roll no!").slideDown();
else if(!(/^[0-9]{2}\/(CSE|IT|ECE|ME|CE|CHE|EE|MME|BT)\/[0-9]{2,3}$/.test($(x).val())))
$("#rollError").css({'background-color':'red','color':'white'}).text("Insert a Valid Roll no").slideDown();
else
$("#rollError").css({'background-color':'#65FF00','color':'green'}).text("Roll no Ok");
}
//Name
else if($(x).attr('name')=="name"){
if(!$(x).val())
$("#nameError").css({'background-color':'red','color':'white'}).text("Please Insert your NAME !!").slideDown();
else if(!(/^[A-Za-z ]+$/.test($(x).val())))
$("#nameError").css({'background-color':'red','color':'white'}).text("Insert a Valid NAME").slideDown();
else
$("#nameError").css({'background-color':'#65FF00','color':'green'}).text("Name Ok");
}
//Phone Number
else if($(x).attr('name')=="phone"){
if(!$(x).val())
$("#phoneError").css({'background-color':'red','color':'white'}).text("Please Insert your Phone Number !!").slideDown();
else if($(x).val()<=1000000000)
$("#phoneError").css({'background-color':'red','color':'white'}).text("Insert a Valid phone Number").slideDown();
else
$("#phoneError").css({'background-color':'#65FF00','color':'green'}).text("Phone Ok");
}
//email
else if($(x).attr('name')=="email"){
if(!$(x).val())
$("#emailError").css({'background-color':'red','color':'white'}).text("Please Insert your Email !!").slideDown();
else if(!(/^\w+@+[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/.test($(x).val())))
$("#emailError").css({'background-color':'red','color':'white'}).text("Insert a Valid Email").slideDown();
else
$("#emailError").css({'background-color':'#65FF00','color':'green'}).text("Email Ok");
}
}
//More Details Updation
$("#update_button").click(function(){
$("input,textarea").removeAttr("disabled");
$(".before").css({'display':'block'}).slideUp(function(){
$(this).remove();
$(".after").slideDown();
$("label").css({'display':'block'}).hide().slideDown();
});
});
$("#set_button").click(function(){
event.preventDefault();
$("#message2").slideUp();
serializedData=$("#update_form").serialize();
var request=$.ajax({
url: "update.php",
type: "post",
data: serializedData
});
request.done(function (response, textStatus, jqXHR){
$("#message2").text(response).css({'display':'inline-block'}).hide().slideDown();
});
request.fail(function (jqXHR, textStatus, errorThrown){
alert("Unable to Handle request please try again later !!");
});
});
//Image Upload
$('#submit_form').on('submit', function(e){
e.preventDefault();
alert("Wait while image is being uploaded");
$.ajax({
url:"upload.php",
method:"POST",
data:new FormData(this),
cache:false,
contentType:false,
processData:false,
success:function(received)
{
$("#message2").html(received);
$('.banner,.title2,.profile_back').fadeTo('slow', 0, function(){
$(this).css({'background-image':'url(img/std_img/'+regno+'.jpg'+"?random="+ new Date().getTime()+'),url(img/banner.jpg)',
'background-size':'cover',
'background-position-x':'0px',
'background-position':'center',
'background-attachment':'fixed'
});
}).fadeTo('slow', 1);
}
});
});