troubleshooting Question

php passing string to javascript

Avatar of ioustinos_sarris
ioustinos_sarrisFlag for Greece asked on
43 Comments1 Solution1268 ViewsLast Modified:
Hi there,
i am trying to pass a json string to the pages javascript via the onload() function of the body.
that string is created in php like that
$json_string = $json->encode($array); and i check the result by echoing i and its valid.

calling onload function
<body onLoad="initialize(<?php echo $init_area_div_num; ?>,<?php echo $last_area; ?>),'<?php echo $json_string; ?>'">

the function initialize()

the first two paraeters are integers ansd appear correctly.
for the third one which is a string i get an error
invalid property id

id is the first of the json objects properties...

moreover i tried to pass a simple string changing the php code to
$json_string = "TEST"; and what i got when the javascript executed was that TEST is TEST was a name of a variable...

obviously i have a problem manipulating my string....any help would be appreciated.
Joe Wu
Developer | Solutions Architect | CTO

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 43 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 43 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros