0

I have an associative array after json_encode like this

{"1":"CourseA", "2":"CourseB"}

and it is stored in a php variable named $jsonObject.Now, I want to send this to a javascript function and use that array inside that function. The function is invoked onclick like this:

 <a href="#" onclick="popup('.$jsonObject.');">link</a>

The problem is: It shows an error:invalid id popup({....

Whats the reason and what should be the solution for that? btw, I am working in moodle and the above link is shown inside a moodle block and declared inside $this->content->text.

1
  • Just leave it as JSON and html encode it into the html. Commented May 30, 2013 at 4:16

1 Answer 1

1

Html encode the JSON to escape special characters,

<a href="#" onclick="popup('.htmlspecialchars($jsonObject).');">link</a>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.