1

I would like to see how can I get the $CITY, $STATE, and $count data to be included in the javascript code ?

Here is the non working code:

<?php echo('<script type="text/javascript"> var address$count = $CITY$STATE');?>

   var map = new google.maps.Map(document.getElementById('map'), { 
       mapTypeId: google.maps.MapTypeId.TERRAIN,
       zoom: 6
   });

   var geocoder = new google.maps.Geocoder();

   geocoder.geocode({'address': address<?php echo($count);?>},

   function(results, status) {
      if(status == google.maps.GeocoderStatus.OK) {
         new google.maps.Marker({
            position: results[0].geometry.location,
            map: map
         });
         map.setCenter(results[0].geometry.location);
      }
   });

   </script> 
<?php
}
?>
</body> 
</html>

Thanks for the help!

4
  • "apart" or "a part"? They mean two opposite things. Also, please do not use non-words like "probpem" to get around que question title filter. Please edit your title into something more informative. Commented Dec 10, 2012 at 18:26
  • @bfavaretto I edited the question, I did not know that the word problem was a non-word, it was just a spelling mistake I did not try to get around anything. But it's still good to know what words I can use in the title, Thank you. Commented Dec 10, 2012 at 19:21
  • My apologies then. I too believed it was a typo, but when I tried to fix it myself, the system didn't let me save the title because of the word "problem". So I just assumed it happened to you too, and that you intentionally tried do get around the filter. Sorry if I was rude. Commented Dec 10, 2012 at 19:34
  • @bfavaretto no, you where not rude, you took the time to read my title/question and this also helps me get a better response and hopefully an answer, so no worries and thank you for your input/help. Commented Dec 10, 2012 at 19:39

3 Answers 3

2

If your variables are correct, javascript usually needs quotes around strings, like so:

<?php 
 echo '<script type="text/javascript"> var address'.$count.' = "'.$CITY.$STATE.'"';
?>

Also, to use PHP variables inside a string would require double quotes, so if you intend to keep the single quotes you would need to concentenate.

Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

<?php echo('
   <script type="text/javascript"> var address' . $count . '= "' . $CITY . $STATE . '"'
);?>

Comments

2

Try:

<?php echo "<script type='text/javascript'> var address".$count." = "".$CITY." ".$STATE."";" ;?>

   var map = new google.maps.Map(document.getElementById('map'), { 
       mapTypeId: google.maps.MapTypeId.TERRAIN,
       zoom: 6
   });

   var geocoder = new google.maps.Geocoder();

   geocoder.geocode({'address': address<?php echo($count);?>},

   function(results, status) {
      if(status == google.maps.GeocoderStatus.OK) {
         new google.maps.Marker({
            position: results[0].geometry.location,
            map: map
         });
         map.setCenter(results[0].geometry.location);
      }
   });

   </script> 
<?php
}
?>
</body> 
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.