- So let us say i have a form with id #form which has two input fields, namely title & price.
- I click on the Edit button somewhere in the application which has data attributes (e.g data-title="Apple" data-price="10")that are to be assigned to the #form upon clicking the button.
- the obvious solution that works is
$("#name").val($(this).data('name')); $("#price").val($(this).data('price')); - This obviously looks bad when you have too many fields. So I am trying to get something like this to work
$('#form').data($(this).data());, more or less in a single like - Have tried this many ways with no success
Any help is appreciated