I have a button that displays a form on my html page. I have a function that gets data from forms:
function getFormData($form){
var unindexed_array = $form.serializeArray();
var indexed_array = {};
$.map(unindexed_array, function(n, i){
indexed_array[n['name']] = n['value'];
});
return indexed_array;
}
The function works well, because I can get data from other forms that were not dynamically created. I create my form this way by clicking the button:
var new_form = document.createElement('form');
new_form.id = "new_form";
existent_div.appendChild(new_form);
new_form.appendChild(input1); (...)
I have one more button which should be responsible for receiving form data. It calls this function, and in the middle of the function I have this:
var new_form_info = getFormData($("#new_form"));
Why is this happening? I am not an experienced programmer, so sorry for any errors ...
source
share