So, i have this section of html:
<input type="text" id="inputA_1" value="ValueA" />
<input type="text" id="inputB_1" value="ValueB" />
<input type="text" id="inputC_1" value="ValueC" />
<input type="text" id="inputD_1" value="ValueD" />
And i want to build this basic java script variable
var postdata = {inputA: 'ValueA',
inputB: 'ValueB',
inputC: 'ValueC',
inputD: 'ValueD'}
In reality there are approximately 100 variables. (Its a template builder).
Currently im doing it like this
function buildPostData(id){
var postdata = {inputA: $("#inputA_"+id).val(), inputB: $("#inputB_"+id).val(), inputC: $("#inputC_"+id).val(), inputD: $("#inputD_"+id).val()};
}
Now, i KNOW there is a better way to do this. Im just not 100% sure on how to use the array.push function properly.
Here is what i have so far:
function buildPostData(id){
var postdata = [];
$("input[id$='_"+id+"']").each(function(){
var id = $(this).attr("id");
var value = $(this).val();
//Now how to i push it into the array properly?
postdata.push(id: value);
});
}
Thanks alot
~Cody Woolaver