var x = 1;
var ctr = 5;
while (x<=ctr){
var ss_+x = $('input[name=IDMenu_'+x+']').val();
x++;
}
As you can see above I have a loop that will iterate through input fields with the name IDMenu_1 through to IDMenu_5. I attempted to make the variable names themselves variable by using the syntax var ss_+x; however this is incorrect and does not work.
If I were to not use a loop, this is what I would be doing:
var ss_1 = $('input[name=IDMenu_1]').val();
var ss_2 = $('input[name=IDMenu_2]').val();
var ss_3 = $('input[name=IDMenu_3]').val();
var ss_4 = $('input[name=IDMenu_4]').val();
var ss_5 = $('input[name=IDMenu_5]').val();
Is it possible to accomplish this within a loop?
var ss_+x- what should that do? Have you had a look at your browser's error console while running the above code?var ss = [];- thenss.push($('input....val());