Last time I asked about the reverse process, and got some very efficient answers. I’m aiming for least lines of code here. I have a form of fields and an associative array in the {fieldname:data} format, I want to populate a corresponding form with it.
Share
When I did this for a project, I found that setting the value of select fields, radio buttons and checkboxes necessitated more complex code, something along the lines of:
I haven’t tested this code so I hope there are no silly syntax errors that I should have caught. Hope this helps.
I am not allowed to comment on the comments here (yet), so …. As noted in the comment, the jQuery .val(val) method handles setting radio buttons,checkboxes and selects.
You will still need to put select[name=…] into your jQuery selector pattern or the select elements won’t be updated.