I have a form with inputs using an array for the name like this:
<input type="text" name="answer[0]" />
Those work fine when I do an ajax post and serialize the form for the data. Now I am trying to pass a dynamic object to jQuery ajax data that will mimic the structure it gets if it were to serialize the form. Here is the code I'm trying for that:
function sliderCalc(){
var step = jQuery('[name="step"]').val();
var max = jQuery('[name="max"]').val();
var min = jQuery('[name="min"]').val();
var count = (max - min) / step;
var sliderData = {};
for(i=0; i<=count; i++){
var value = min + (step * i);
sliderData.answers[i] = value; // key => value created here
}
return sliderData;
}
I'm getting this error:
Uncaught TypeError: Cannot set property '0' of undefined
Does anyone have a good solution for this?