Say I have a hash and I want to enter it as val()
val()
$("#form_attribute").val( hash )
It is saved as the string "[Object, object]"
"[Object, object]"
How to save it as a hash, and then allow the form to send this hash to my server?
If you want to convert the object / value to a JSON string, you can use JSON.stringify to do something like this:
JSON.stringify
$("#form_attribute").val(JSON.stringify(hash))
This is a built-in method for the latest browsers, which converts the object to the JSON notation representing it. If any browser does not support it, your page should have several polyfills to support
Literature:
window.JSON
You can save it as a JSON string:
$('#form_attribute').val(JSON.stringify(hash));
Or you can save the original object in the data attribute:
$('#form_attribute').data('hash', hash);