Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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!

share|improve this question
 
"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. –  bfavaretto Dec 10 '12 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. –  compcobalt Dec 10 '12 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. –  bfavaretto Dec 10 '12 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. –  compcobalt Dec 10 '12 at 19:39
add comment

3 Answers

up vote 2 down vote accepted

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.

share|improve this answer
 
Got it, Thank you so much for your help. –  compcobalt Dec 10 '12 at 19:16
add comment

Try this:

<?php echo('
   <script type="text/javascript"> var address' . $count . '= "' . $CITY . $STATE . '"'
);?>
share|improve this answer
 
This works also, Thanks so much. –  compcobalt Dec 10 '12 at 19:16
add comment

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>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.