Noah Noah - 1 month ago 18
jQuery Question

Elements of form to javascript object using JQuery

What would be the way best to convert form elements to an JavaScript Element?

I would like some automatic way to build JavaScript objects, without having to loop each element. I do not want any strings returned like in

var formData = f.serialize();
.

My HTML

<script type="text/javascript">
$(function() {
$("#sendrfr").click(function() {

var f = $("#Commtnx");
var formData = f.serialize();

alert(formData);
});
});
</script>

<div id="outter">
<form id="Commtnx" action="/Home/Test1" method="post" name="down">
<div id="inner">
<input id="input1" type="text" value="2" />
</div>
</form>
</div>

<input type="submit" id="sendrfr" />

Answer

serializeArray() does just that.

 $('form').on('submit',function(e){
    e.preventDefault();
    var output = $(this).serializeArray();
    console.log(output);
 });
Comments