I'm building a javascript to submit an html form automatically using jQuery. I'm wondering if it's possible to create a javascript method that will return a map of all form elements and values if given an identifier to find the form with. I'd rather use such a method than manually specifying jQuery selectors for each form element.
function form_submit(){
jQuery.ajax({
type: 'post',
url: '/signup/',
data: map_form_elements_values('my_form'),
success: function(data, textStatus, jqXHR){
//foo
}
});
return false;
}
<form id="my_form" action="">
<input class="" id="name" type="text" name="last-name" />
<select class="" id="fruit" type="select" name="fruit-name" />
<option>bananas</option>
</select>
</form>
the goal would be to have map_form_elements_values('my_form') return a map that can be used by the ajax function. Does anyone know how to do this?
.serializeArray()- api.jquery.com/serializeArray