javascript - Passing Array From PHP to JQuery json_encode -
i have html form generated php has dropdown of voucherproviders.
i want select provider , have populate form editing.
here jquery code:
$(document).ready(function() { $(document).on('change','#id_voucherprovider',function(){ var voucher_providers = <?php echo json_encode($voucher_providers); ?>; //the value have got drop down is.... var value = $('#id_voucherprovider option:selected').val(); var vendortext = $('#id_voucherprovider option:selected').text(); //so voucher provider alert(vendortext); $('.ftext input').val(vendortext); $("textarea#id_vendornotes").val(voucher_providers[value]); }); });
voucherproviders not being passed jquery despite echo json_encode($voucher_providers);
code working when inline php code.
it seems return null array. can see wrong?
many thanks
dave
var voucher_providers = <?php echo json_encode($voucher_providers); ?>;
json_encode returns string, unless parsed not usable. use jquery .parsejson , should have better results. :)
var jsonstring = <?php echo json_encode($voucher_providers); ?>; var voucher_providers = $.parsejson(jsonstring);
Comments
Post a Comment