Jump to content

using php variables in external js function


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



    <div class="row">
    initMap($latitude, $longitude,$row['Latitude'],$row['Longitude']);
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.