-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.js
161 lines (132 loc) · 4.68 KB
/
form.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
$(document).ready(function (){
currdate=new Date();
//console.log(currdate);
diff= currdate.getYear()-21;
console.log(diff);
maxdate = new Date(diff,0,1);
//$('input[type="date"]').attr('min','')
$.datepicker.setDefaults({
dateFormat: 'dd-mm-yyyy',
// minDate:'1-1-1980',
maxDate: maxdate
});
$("input[type=file]").change(function (){ //input having the attribute is in square bracs
console.log("file uploaded");
// console.log($(this));
readURL(this);
});
function readURL(input)
{
if(input.files && input.files[0])
{
var reader = new FileReader();
// reader.readAsDataURL(input.files[0]);
reader.onload=function(e){
window.sessionStorage.setItem('photo',e.target.result);
$('#image_upload').attr('src',e.target.result);
$('#image_upload').css({
'width': '100px',
'height': '100px'
})
}
reader.readAsDataURL(input.files[0]);
}
}
$("#birthDate").datepicker({
showOn:"button",
numberOfMonths:2
})
$('#firstName').keypress(function (e){
//console.log(e.charCode);
var regex = new RegExp("^[A-Z a-z]*$");
var str = String.fromCharCode(!e.charCode ? e.which :e.charCode)
if(regex.test(str))
return true;
e.preventDefault();
return false;
});
$('#contact').keypress(function (e){
var reg = new RegExp("^[0-9]{0,10}$");
var str =String.fromCharCode(!e.charCode ? e.which :e.charCode);
if(reg.test(str))
return true;
e.preventDefault();
return false;
});
var count =0 ;
$('#address').keypress(function (e){
var reg = new RegExp("^[a-zA-Z0-9\-\/\,\\s\.]+$");
if(e.charCode==8)
count--;
if(e.charCode!=8){
var str =String.fromCharCode(!e.charCode ? e.which :e.charCode);
if(reg.test(str)){
count++;
if(count<5)
$('#message').text("Minimum 5 required");
if(count>=5 && count<=100)
$('#message').text('');
if(count>100){
$('#message').text('Exceeded the limit');
return false;
}
return true;
}}
e.preventDefault();
return false;
});
$("#state").autocomplete({
source: function (request, response) {
$.ajax({
url: "http://gd.geobytes.com/AutoCompleteCity?callback=?&q="+request.term,
type: "GET",
contentType: 'application/json; charset=utf-8',
dataType: "jsonp",
success: function (data) {
response(data);
$.each(data, function (item, value) {
console.log(value);
});
},
error:function(msg)
{
console.log(msg);
}
});
}
});
$("#regForm").submit(function(){
console.log("submitted success");
obj={
FirstName:'',
Email:'',
Password:'',
dob: new Date(), //to know what is the type of date
Gender:'',
Address:'',
State:'',
Contact:'',
photo:'',
}
obj.FirstName=$('#firstName').val();
obj.Email=$('#email').val();
obj.Password=$('#password').val();
obj.dob=$('#birthDate').val();
obj.Gender=$(':radio:checked').val(); //wtever the value has been selected it has to be stored $('#for muliples:radio:checked').val()
if(window.sessionStorage.getItem('photo')!=undefined)
{
obj.photo=window.sessionStorage.getItem('photo');
/*for var data=[];
checkbox $(":checkbox:checked").each(
function(){
data.push($(this).val());
})*/
}
obj.Address=$('#address').val();
obj.State=$('#state').val();
obj.Contact=$('#contact').val();
console.log(obj);
console.log(JSON.stringify(obj));
return false; //so that the form should nto be refreshed
})
})