Reply to Re: Javascript function can't read variables set by php

Your name:

Reply:


Posted by Dan Bee on 10/02/06 17:41

Thanks all,

The idiotic error I made is that in the outputted array, I did not put
quotation marks around the strings. Doh.



Jerry Stuckle wrote:
> dan... wrote:
> > 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"...
> >
>
> I suspect you have short tags disabled in your php.ini file.
>
> Instead of '<?= ' you should use '<?php echo '.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================

[Back to original 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

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация