You need to sign in to do that
Don't have an account?

JavaScript won't load when !{Account.BillingStreet} points to a two-line address.
I have the following code for pulling up driving directions from SalesForce. Works amazingly well as long as the address is on one line. When it's a two-line address, none of the script will load. I've tried putting the variable into a try/catch rule, but that doesn't solve the problem. Advice?
<apex:page standardController="Account" showHeader="false" sidebar="false" standardstylesheets="false"> <script> // SOFTWARE BUG!!! MULTI-LINE ADDRESS AND PAGE LOADS W/O JAVASCRIPT! var currentLocation; function getLocation() { navigator.geolocation.getCurrentPosition(showPosition); } function showPosition(position) { try { var address = '{!Account.BillingStreet}' + '{!Account.BillingCity},' + '{!Account.BillingState}' + '{!Account.BillingPostalCode}'; var destination = address.split(' ').join('+'); } catch(err) { alert('Street address must be on one line to use this function.'); window.close(); } currentLocation = position.coords.latitude + ',' + position.coords.longitude; if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/iPod/i))) { var URL = 'http://maps.apple.com/?saddr=' + currentLocation + '&daddr=' + destination; window.open(URL,'_parent'); } else { var URL = 'https://maps.google.com/maps?saddr=' + currentLocation + '&daddr=' + destination; window.open(URL,'_parent'); } } function init() { document.write('<div style="position:absolute;top:50%;left:50%;">loading...</div>'); getLocation(); } window.onload = new function() { init(); }; </script> </apex:page>
Problem resolved by replacing {!Account.BillingStreet} with {!SUBSTITUTE(JSENCODE(Account.BillingStreet),'\r\n',' ')}
All Answers
Problem resolved by replacing {!Account.BillingStreet} with {!SUBSTITUTE(JSENCODE(Account.BillingStreet),'\r\n',' ')}