Hi,
I attempted by mixing the codes for the GPS and Autocomplete by using a switch case. Only the GPS executes.
Whatever else I tried, the autocomplete just does not execute when it is mixed with the GPS code.
LSS attached and here is the code:
Location:<button class="gpsLink" type="button">Get GPS Data</button><script type="text/javascript" charset="utf-8">
<link href="/upload/surveys/{SID}/files/jquery-ui.min.css" rel="stylesheet" type="text/css" /> <script src="/upload/surveys/{SID}/files/jquery-ui.min.js"></script> <script src="/upload/surveys/{SID}/files/jquery.csv.min.js"></script> <script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:complete',function() {
var x = 0;
myFunction(x);
$('.gpsLink').click(function(){
var x = 1;
myFunction(x);
});
function myFunction(x) {
switch (x) {
case 0:
// Identify this question
var thisQuestion = $('#question{QID}');
// Hide the second input
$('.question-item:eq(1)', thisQuestion).hide();
var url = "/upload/surveys/{SID}/files/NAMES_cleaned.csv";
var Names = [];
var Coords = { };
$.get(url, function(data){
fullArray = $.csv.toArrays(data);
$(fullArray).each(function(i, item){
Names.push(item[0]);
Coords[item[0].toLowerCase()] = item[1];
});
// Initiate the Autocomplete plugin
$('input[type=text]:eq(0)', thisQuestion).autocomplete({
minLength: 2,
source: Names,
select: function(event, ui) {
$('input[type=text]:eq(1)', thisQuestion).val(Coords[ui.item.value.toLowerCase()].replace(/;/, ' '));
// Auto-submit
if($.trim($('input[type=text]:eq(1)', thisQuestion).val()) != '') {
$('#ls-button-submit').trigger('click');
}
}
}).on('change', function(e) {
$('input[type=text]:eq(1)', thisQuestion).val(Coords[$.trim($(this).val()).toLowerCase()].replace(/;/, ' '));
// Auto-submit
if($.trim($('input[type=text]:eq(1)', thisQuestion).val()) != '') {
$('#ls-button-submit').trigger('click');
}
});
});
alert("Case 0");
break;
case 1:
getGPS();
function getGPS() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showGPS, gpsError);
} else {
$("#answer{SGQ}SQ003").val('No GPS Functionality');
}
}
function gpsError(error) {
alert('GPS Error: '+error.code+', '+error.message);
}
function showGPS(position) {
$("#answer{SGQ}SQ003").val(position.coords.latitude+';'+position.coords.longitude).trigger('keyup');
}
alert("Case 1");
break;
}
}
});
</script>
Any idea?
Thanks and regards
The topic has been locked.