I have a zend form select element that calls a javascript function onchange. The following:
$element->setAttribs(array( 'onchange' => 'toggleSelect(this.value, ' . json_encode($this->_testData) . ')'));
The problem is, both the ZEND onchange and the json_encode use double quotes, so it becomes:
<select onchange="toggleSelect(1, {"foo" : "bar"})"></select>
Which complains about an invalid property id. I’m thinking it is the double quotes that are causing the problem, but don’t know how to fix.
Try
Using htmlspecialchars you should end up with
which should be valid html and still interpret your argument as a valid JSON object.