HTML & PHP:
<select id="package">
<?php $package_size_array = array('size_a' => 70, 'size_b' => 90, 'size_c' => 130); ?>
<option value="size" id="<?php echo json_encode($package_size_array, JSON_PRETTY_PRINT); ?>">Size</option>
<!--Some more <option>s here...-->
</select>
JavaScript:
$(document).ready(function() {
$('select#package').change(function() {
var id = $(this).children(':selected').attr('id');
alert(JSON.parse(id)); /* Line 217. in functions.js file */
});
});
Problem: Chrome and probably other browsers' console prints:
Uncaught SyntaxError: Unexpected end of input functions.js:217
(anonymous function) functions.js:217
jQuery.event.dispatch jquery.js:4371
elemData.handle
idis just a string, it's not a JSON object.id="JSON"and the JSON also contains double quotes, so his quotes are all messed up.