Link to home
Start Free TrialLog in
Avatar of bhinshawnc1
bhinshawnc1

asked on

Replace text in script with variable value

I want to replace 'Dallas, TX' with the variables from geocity and geostate. The #set_center.city# and #set_center.state# value comes from a query within coldfusion code on the page

How can I do that? Thanks

function reCenter() {
	// alert(0);
	var geocity = '#set_center.city#';
	alert(geocity);
	var geostate = '#set_center.state#';
	alert(geostate);
	var geocoder = new GClientGeocoder();
	geocoder.getLatLng(
		'Dallas, TX',
	    function(point) {
	      if (!point) {
	        alert(address + " not found");
	      } else {
			map=ColdFusion.Map.getMapObject("mainMap");
			ColdFusion.Map.setZoomLevel('mainMap', 8);
			map.setCenter(point);
	      }
	    }
	)
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bhinshawnc1
bhinshawnc1

ASKER

final code

function reCenter() {
	// alert(0);
	var geocity = '#set_center.city#';
	alert(geocity);
	var geostate = '#set_center.state#';
	alert(geostate);
	var geocoder = new GClientGeocoder();
	geocoder.getLatLng(
		geocity +', ' + geostate,
	    function(point) {
	      if (!point) {
	        alert(address + " not found");
	      } else {
			map=ColdFusion.Map.getMapObject("mainMap");
			ColdFusion.Map.setZoomLevel('mainMap', 8);
			map.setCenter(point);
	      }
	    }
	)
}

Open in new window

I'd also suggest using jsStringFormat() to escape any special characters, like single quotes, that might interfere with the JS code.  ie

     var geocity = '#jsStringFormat(set_center.city)#';
     var geostate = '#jsStringFormat(set_center.state)#';


http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6e31.html