i'm getting the data from a form when it is submitted like this
values = {};
$("#myForm").submit(function(){
$.each($('#myForm').serializeArray(), function(i, field) {
if(field.name != 'r'){
values[field.name] = field.value;
}
});
return false;
});
The problem is that i want to do that multiple times and store all the data in the var values using field.name as a keys and the values as an array to compare it in php i would do values[field.name][] = field.value; is there any similar syntax in js ?
Yeah, you can add multiple values using the Array.push method. But first, you must define values[field.name] as array, like this:
values[field.name] = [];
values[field.name].push(somevalue);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With