Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7640045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:34:44+00:00 2026-05-31T08:34:44+00:00

Im having problems passing PHP Strings to Javascript functions, I’v read a number of

  • 0

Im having problems passing PHP Strings to Javascript functions, I’v read a number of the post regarding this problem and tried several methods but none of them have worked for me.
basically I have two functions one written in PHP that pulls information from a database and the other written in Javascript designed to allow me to geocode an address for google maps and pass some info to be added to the info window, the two bits of code are shown below:

PHP

try {
        $bubbleData = $dbConnection->getBubbleData();
    } catch (Exception $e) {
        echo "The following error occoured while attempting to get Google map info window data" .
        " " . $e->getMessage() .
        " " . "In file" .
        " " . $e->getLine() .
        " " . "on line" .
        " " . $e->getLine();
    }

    if (mysql_num_rows($bubbleData) == 0) {
        echo "No Placement data found to populate map";
    } else {
        while ($row = mysql_fetch_array($bubbleData)) {
            $companyName = $row['Company_Name'];
            $title = $row['Title'];
            $address_1 = $row['Address_Line_1'];
            $address_2 = $row['Address_Line_2'];
            $address_3 = $row['Address_Line_3'];
            $address_4 = $row['Address_Line_4'];
            $post_Code = $row['Post_Code'];
            $forename = $row['Forename'];
            $surname = $row['Surname'];

            $fullAddress = $address_1 . " " . $address_2 . " " . $address_3 . " " . $address_4 . " " . $post_Code;

            $partAddress_1 = $address_1 . " " . $address_2;
            $partAddress_2 = $address_3 . " " . $address_4;

            $infoText = "<h4>" . $title . "</h4>" .
                    '<b>' . "Company name:" . '</b>' . " " . $companyName .
                    "</br>" .
                    "<b>" . "Employee name:" . '</b>' . " " . $forename . " " . $surname . '</br>' .
                    "<b>" . "Company address:" . "</b>" . " " . $partAddress_1 . '</br>' .
                    $partAddress_2 . '</br>' . $post_Code;

    echo "<SCRIPT LANGUAGE='javascript'>
    geocodeAddress(<?php echo json_encode($fullAddress);?>,<?php echo json_encode($infoText);?>);
    </SCRIPT>'";
        }
    }

Javascript

function geocodeAddress (address,infoText) {

            var geocoder = new google.maps.Geocoder();
            geocoder.geocode( {'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    loadMarker(results[0].geometry.location,infoText,address);
                    latlngArray.push(results[0].geometry.location);
                } else {
                    alert("Geocode was not successful for the following reason: " +" "+  status);
                }
            });
        }re

Now I know that the two work fine individually but whenever I try to call the javascript in side the PHP and pass it the variables I ge the following error in firebug:

Invalid value for property address:

I’ve been trying to make this happen all day, Ive used regexs plane echos and the json_encode() function and nothings worked can anyone help?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:34:46+00:00Added an answer on May 31, 2026 at 8:34 am

    You have nested <?php ?> inside PHP code, which will not be interpreted as PHP. Rather, it just prints into your output as a string.

     // Instead of
     echo "<SCRIPT LANGUAGE='javascript'>
        geocodeAddress(<?php echo json_encode($fullAddress);?>,<?php echo json_encode($infoText);?>);
        </SCRIPT>'";
    
     // Change to
     echo "<SCRIPT LANGUAGE='javascript'>
        geocodeAddress(" . json_encode($fullAddress) . "," . json_encode($infoText) . ");
        </SCRIPT>'";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems passing utf-8 strings to javascript (ajax). Currently i'm using rawurlencode on
I'm having a problem passing strings that exceed 80 characters in JSON. When I
I am having a problem passing a json string back to a php script
I am having a problem in passing parameters to webservice which except POST data
I'm having problems passing parameters (in this case, @plan_id) to the next page (new_user_url).
I am having problems passing javascript values between frames in chrome. In other browsers
so i am having a problem passing php session variables to multiple pages. Essentially
Im having problems displaying records to my view when passing viewdata to a user
I'm having some problems with Jquery UI Dialog and TinyMCE. Passing data to a
I am having some problems parsing this piece of XML using SimpleXML. There is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.