Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a json object to the hidden input

I want to store a json object into a hidden input for submit and send to server side.

<input type='hidden' id='permissions' name='permissions' />

During submission :

<input type='hidden' id='permissions' value='[{"1" : "deny", "2": "deny", "5" : "allow"}]' name='permissions' />

I used bellow line but not working :

$('#permissions').val(json_object);

like image 723
Behzad Azizan Avatar asked Dec 03 '25 09:12

Behzad Azizan


1 Answers

Use JSON.stringify like

$('#permissions').val(JSON.stringify(json_object));
like image 178
AmmarCSE Avatar answered Dec 06 '25 00:12

AmmarCSE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!