I have this code which works.
$(document).ready(function(){
$('form').live('submit', function(){
// have to do it like this to simulate my problem
var aform = $(this);
var dat = { "TITLE" : "55h5", "OWNER" : "fff" };
$('#template').tmpl(dat).prependTo('#content');
return false;
});
});
But what I would like is to take the values from aform and insert them directly into
$('#template').tmpl( HERE ).prependTo('#content');
The data from the form have do accessed through aform to simulate my problem. Can this be done?
Here is the problem illustrated
You could use
.serializeArray(), and then loop over it to create the right data structure:You could do the same with plain JavaScript (is probably faster):