Jump to content
New Reality: Ads For Members ×

using php variables in external js function


unistake

Recommended Posts

Hi all,

 

I am trying to pass 4 variables from one php page to another php page containing a google maps api.

 

The variables I am passing are geo coordinates.

 

at the end I want to show the map on my php page however I am struggling with linking php and javascipt together.

 

This is what I have so far:

 

external function page: http://pastebin.com/NAKHmKxW

 

[PART OF MAIN PHP PAGE]

    <div class="row">
    <?php
    include_once("function_maps.php");
    initMap($latitude, $longitude,$row['Latitude'],$row['Longitude']);
    ?>
    </div>

I strongly recommend that you stop writing this PHPHTMLCSSJavaScript mishmash. It will lead to errors and cross-site scripting vulnerabilities all over the place, and you'll quickly end up with an unreadable, unmaintainable mess of spaghetti code.

 

Keep your languages separate. Style declarations belong into external CSS files, and JavaScript code belongs into external JavaScript files. Then use Ajax to load server-provided data (like the content of PHP variables) into your JavaScript functions. Alternatively, you can embed the data into a hidden HTML element and then parse it with JavaScript. In any case: Do not echo your PHP variables directly into a JavaScript context.

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.