-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexform.js
More file actions
119 lines (112 loc) · 3.22 KB
/
indexform.js
File metadata and controls
119 lines (112 loc) · 3.22 KB
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
var geocoder;
$(document).ready(function() {
$("#birthyear").val("year");
$("#birthyear").focus(function() {
$(this).val('');
});
$("#currentaddress").val("address");
$("#currentaddress").focus(function() {
$(this).val('');
});
$("#birthaddress").val("address");
$("#birthaddress").focus(function() {
$(this).val('');
});
initialize();
});
function initialize(){
geocoder = new google.maps.Geocoder();
var ne = new google.maps.LatLng(59.44507, 3.86718);
var sw = new google.maps.LatLng(48.10743, -13.18359);
var birthaddress;
var currentaddress;
var birthcountry;
var currentcountry;
$(function() {
$("#birthaddress").autocomplete({
source: function(request, response) {
geocoder.geocode( {
'address': request.term,
'region': 'UK',
'bounds': new google.maps.LatLngBounds(sw, ne)
},
function(results, status) {
response($.map(results, function(item) {
for (var i = 0; i < item.address_components.length; i++) {
if ( item.address_components[i].types[0] == 'country' ) {
birthcountry = item.address_components[i].short_name;
}
}
return {
label: item.formatted_address,
value: item.formatted_address,
latitude: item.geometry.location.lat(),
longitude: item.geometry.location.lng(),
birthcountry: birthcountry
}
}));
})
},
change: function( event, ui ) {
if ( !ui.item ) {
$("#birthaddress").val('address');
}
else {
$('#birthlatitude').val(ui.item.latitude);
$('#birthlongitude').val(ui.item.longitude);
$('#birthcountry').val(ui.item.birthcountry);
}
}
});
$("#currentaddress").autocomplete({
source: function(request, response) {
geocoder.geocode( {
'address': request.term,
'region': 'UK',
'bounds': new google.maps.LatLngBounds(sw, ne)
},
function(results, status) {
response($.map(results, function(item) {
for (var i = 0; i < item.address_components.length; i++) {
if ( item.address_components[i].types[0] == 'country' ) {
currentcountry = item.address_components[i].short_name;
}
}
return {
label: item.formatted_address,
value: item.formatted_address,
latitude: item.geometry.location.lat(),
longitude: item.geometry.location.lng(),
currentcountry: currentcountry
}
}));
})
},
change: function( event, ui ) {
if ( !ui.item ) {
$("#currentaddress").val('address');
}
else {
$('#currentlatitude').val(ui.item.latitude);
$('#currentlongitude').val(ui.item.longitude);
$('#currentcountry').val(ui.item.currentcountry);
}
}
});
// double-check those values are input
$('#entryform').submit(function() {
var birthvalue = $("#birthaddress").val();
var currentvalue = $("#currentaddress").val();
if ( birthvalue == 'address'
|| birthvalue == ''
|| currentvalue == 'address'
|| currentvalue.val == '') {
alert('Hey! You need to fill in that form...')
return false;
}
else {
$('#entryform').submit();
}
});
});
}