I have the following two variables. I will send the data variable to the server, and upon return, want to access the various original values.
I could do some sort of eq(1).val() approach to either the data or raw variable, but then need to make sure I am accessing them in the right order which might result in future maintenance issues. Or I can get the values from the original DOM using the name selector, but it seems like I am doing the work twice. Or I can add IDs as well as names to the original form, but that seems like a waste.
Ideally, I would be able to convert the form’s name/value to some sort of object, but unlike serializeArray would not make an array, but have the value directed tied to the name. For instance, if my form had <input name="foo" value="bar">, I would be able to access the value as newObject.foo.
Any suggestions on the best way to do this?
var raw=$("#form_id").find('input,select');
var data=raw.serializeArray();
You can do this by directly accessing the form: