Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    You've got htmlspecialchars and json_encode backwards. While using json_encode to prepare data for JavaScript is generally fine, you're putting JS in HTML not the other way around. If, for example, $object['name'] ever contained a " character then you'd break your data because it would be decoded to " in the middle of a string delimited with " before being passed to the JS engine for parsing. Commented Apr 29 at 10:45
  • 1
    Errors aside, this question had 40 answers before you added this one. Yours lacks any kind of explanation as to how it solves the problem. Is it really an addition worth making? Commented Apr 29 at 10:46
  • 1
    Note that, this century, the use of onclick attributes is not recommended. Commented Apr 29 at 10:47
  • I spent a half day to find the solution that works in loop. And the most what helps me the similar examples. So I decided to sharie my example with the hope that it will be useful to someone and save time, as other examples provided on stackoverfolw save me time. Commented Apr 30 at 8:54