Page 1 of 1

Custom javascript calls

Posted: Sat Dec 01, 2012 10:13 pm
by Joe Bohen

Hi,

I have a custom javascript file in my test app on a button event on a page I am calling:

tester();

the code in the javascript file named 'main' is simply:

Function tester() {
alert('Success');
}

I don't get the alert, I have other code that is not working!

Why does this function call not work?


Custom javascript calls

Posted: Sat Dec 01, 2012 11:16 pm
by maxkatz

Function -- function


Custom javascript calls

Posted: Sun Dec 02, 2012 12:19 am
by Joe Bohen

Hi Max,

Sorry about the typo! The actual event being called is:

function tester() {
alert('Success');
}

I only placed this function in the script to test the JavaScript file 'main' to see if it was being called when other functions did not appear to be getting called.

The app is shared to support@tiggzi.com, the function is being called from the click event attached to 'mobilebutton1_9' on the 'map_pge'.

Thanks for your time,
Joe


Custom javascript calls

Posted: Sun Dec 02, 2012 2:52 am
by maxkatz

Can you show exactly where you defined the JavaScript and where/how you invoke it?


Custom javascript calls

Posted: Sun Dec 02, 2012 7:53 am
by Joe Bohen

Hi Max,

The code I was trailing was provided by Marina Brodina in responce to another users question. I placed this in the javascript file in my project and was calling it on a click event on a button on the page.The function is below and the code in the click event was originally:

initiate_geolocation();
;
When this did not work I placed the tester function in the javascript and replaced the original call on the buttons click event to try to pop an alert purely to prove if
the script was getting called, this did not work either.

Regards,
Joe

The script file 'main':

function initiate_geolocation() {
navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors);
}
function handle_errors(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED: alert("GPS function not available right now");
break;
case error.POSITION_UNAVAILABLE: alert("Location services not turned on! Please enable location services prior to continuing.");
break;
case error.TIMEOUT: alert("retrieving position timed out");
break;
default: alert("unknown error");
break;
}
}
function handle_geolocation_query(position){
alert('Lat: ' + position.coords.latitude +
' Lon: ' + position.coords.longitude);
}

var lat;
var lon;

var onSuccess = function(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;

Code: Select all

  var location = new google.maps.LatLng( lat,lon); 

var myOptions = {
zoom: 4,
center: location,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

var map = new google.maps.Map($('div[dsid="mapa"]').get(0), myOptions);

var marker = new google.maps.Marker({
position: location,
map: map,
title:"Hello World!"
});

// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}

Code: Select all

 function testalert(){ 
     alert('Test Alert'); 
 }

Custom javascript calls

Posted: Sun Dec 02, 2012 4:27 pm
by Joe Bohen

Hi Max,

I found the main issue was the naming of the javascript file 'main' was causing a conflict! I deleted this and replaced it with a new file, this corrected a lot of the issues.

My last problem is generating the location marker on the map, I get an error that is happening at the end of the code which says' TypeError: Cannot read property 'offsetWidth' of undefined' does this mean the div mapa is not found if so how do I fix it?

initiate_geolocation();
function initiate_geolocation() {
navigator.geolocation.getCurrentPosition(handle_geolocation_query,handle_errors);
}
function handle_errors(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED: alert("GPS function not available right now");
break;
case error.POSITION_UNAVAILABLE: alert("Location services not turned on! Please enable location services prior to continuing.");
break;
case error.TIMEOUT: alert("retrieving position timed out");
break;
default: alert("unknown error");
break;
}
}
function handle_geolocation_query(position){

var location = new google.maps.LatLng(position.coords.latitude , position.coords.longitude);

Code: Select all

 var myOptions = { 

zoom: 4,
center: location,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

Code: Select all

 var map = new google.maps.Map($('div[dsid="mapa"]').get(0), myOptions); 

var marker = new google.maps.Marker({
position: location,
map: map,
title:"Hello World!"
});

alert('Lat: ' + position.coords.latitude +
' Lon: ' + position.coords.longitude);
}


Custom javascript calls

Posted: Sun Dec 02, 2012 11:19 pm
by Joe Bohen

Hi Max,

Got this sorted now thanks for your support. The big issue was the javascript file name 'main' and debugging in chrome rather on a device. Lots to learn I dare say I will be back!!!

Regards,
Joe