jQuery echo a statement in a textbox if a value is greater than another -
i have code calculates mileage both point , point b. if mileage less 75 miles away either point or point b, want return "free" however, if more 75 miles away both want return statement "you charged expenses".
i thought handle simple if, else if , else statements, it's not working @ all:
function initialize() { directionsdisplay = new google.maps.directionsrenderer(); } var directionsservice = new google.maps.directionsservice(); var directionsservice2 = new google.maps.directionsservice(); function calcroute() { var distance1input = document.getelementbyid("distance1"); var mileageinput = document.getelementbyid("mileage"); var start = "de75 7ah"; var end = document.getelementbyid("end").value; var request = { origin:start, destination:end, travelmode: google.maps.directionstravelmode.driving }; directionsservice.route(request, function(response, status) { if (status == google.maps.directionsstatus.ok) { directionsdisplay.setdirections(response); distance1input.value = math.round(response.routes[0].legs[0].distance.value / 1609.344); } }); //second route var distance2input = document.getelementbyid("distance2"); var start2 = "al8 6re"; var end = document.getelementbyid("end").value; var request2 = { origin:start2, destination:end, travelmode: google.maps.directionstravelmode.driving }; directionsservice2.route(request2, function(response, status) { if (status == google.maps.directionsstatus.ok) { directionsdisplay.setdirections(response); distance2input.value = math.round(response.routes[0].legs[0].distance.value / 1609.344); } }); //mileage cost var mileagecost = math.round(((response.routes[0].legs[0].distance.value / 1609.344)-75)+100); var derbydistance = distance1input.value; var londondistance = distance2input.value; if (derbydistance < 75) { mileageinput.value = 'free'; } else if (londondistance < 75) { mileageinput.value = 'free'; } else { mileageinput.value = 'you charged expenses'; } }
the part of code in question @ bottom trying return statements based on how far away end point is.
you can see script in action here: http://www.samskirrow.com/projects/distr_maps/index2.html
thanks help
response unknown outside of .route
method calls. should pass it, way :
function initialize() { directionsdisplay = new google.maps.directionsrenderer(); } var directionsservice = new google.maps.directionsservice(); var directionsservice2 = new google.maps.directionsservice(); function calcroute() { var distance1input = document.getelementbyid("distance1"); var mileageinput = document.getelementbyid("mileage"); var start = "de75 7ah"; var end = document.getelementbyid("end").value; var request = { origin:start, destination:end, travelmode: google.maps.directionstravelmode.driving }; directionsservice.route(request, function(response, status) { if (status == google.maps.directionsstatus.ok) { directionsdisplay.setdirections(response); distance1input.value = math.round(response.routes[0].legs[0].distance.value / 1609.344); displayexpenses(response); } }); //second route var distance2input = document.getelementbyid("distance2"); var start2 = "al8 6re"; var end = document.getelementbyid("end").value; var request2 = { origin:start2, destination:end, travelmode: google.maps.directionstravelmode.driving }; directionsservice2.route(request2, function(response, status) { if (status == google.maps.directionsstatus.ok) { directionsdisplay.setdirections(response); distance2input.value = math.round(response.routes[0].legs[0].distance.value / 1609.344); displayexpenses(response); } }); function displayexpenses(response){ var mileagecost = math.round(((response.routes[0].legs[0].distance.value / 1609.344)-75)+100); var derbydistance = distance1input.value; var londondistance = distance2input.value; if (derbydistance < 75) { mileageinput.value = 'free'; } else if (londondistance < 75) { mileageinput.value = 'free'; } else { mileageinput.value = 'you charged expenses'; } } }
Comments
Post a Comment