You are here: Re: Javascript function can't read variables set by php « PHP Programming Language « IT news, forums, messages
Re: Javascript function can't read variables set by php

Posted by Kimmo Laine on 10/02/06 07:03

<dan.cao.nguyen@gmail.com> wrote in message
news:1159762503.749397.173870@i42g2000cwa.googlegroups.com...
> OK, I've basically copied this code ad verbatim from a book to
> test...what I have is an index.html page that refers to "map_data.php"
> and "map_functions.js"...
>
> map_data.php draws some coordinates from a database and outputs them
> into an array called markers. However, when I load up the index.html
> page, it says "markers" is undefined...
>
> Here's the code in map_data.php:
>
> var markers = [
> <?php while($row = mysql_fetch_assoc($result)): ?>
> <?= $joiner ?>
> {
> 'latitude': <?= $row['latitude'] ?>,
> 'longitude': <?= $row['longitude'] ?>,
> 'lawyer': <?= $row['lawyer']?>,
> 'city': <?= $row['city']?>,
> 'business_name': '<?= addslashes($row['business_name'])?>',
> 'address': '<?= addslashes($row['address'])?>'
> }
> <?
> $joiner = ',';
> ?>
> <?php endwhile; ?>
> ];
>
> I can't get anything in the map_functions.js to read this markers
> array, even if it's a simple alert call like
> "alert(markers[3].longitude"...


Tried viewing the source? It would be very helpful if you could show what
php actually outputs there. Since markers is undefined, are you sure you've
got the map_data.php inside a javascript tag? As in:

<script type="text/javascript">
<?php require(map_data.php ?>
</script>



And I just gotta say... You're actually using while(): endwhile! Burn the
witch! Vade retro satana! (Nothing wrong with the syntax though, it IS valid
php, but man, it's just unorthodox!)

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti pδivittyvδ nettisarjis
spam@outolempi.net || Gedoon-S @ IRCnet || rot13(xvzzb@bhgbyrzcv.arg)

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация