So, I have several inputs with a name session, and they increase .... session0 session1 session2. If I want to run them through a loop, how would I do it. I am using jquery.
eg..
for(i=0,i<10,i++)
{
var num = (session + i).value + i;
}
So, I want the loop to go through all the inputs with a prefix session and output their values to a variable. This output may fall into an array. if the array will obviously be more like.
num[i] = stuff+i;
thank.
Ok, I'm done with JavaScript. Thanks for all the help, it works great. here was the final code.
function get()
{
var alldata;
var values = [];
$("input[name^='media']").each(function(i, anInput) {
var check = values[i] = $(anInput).attr('checked');
if(check == true)
{
var ID = "session" + i;
var type = $(anInput).attr('value');
if(i > 9)
{
var cont = "#ex"+ i;
}
else{
var cont = "select[name='" + ID + "']";
}
var scope = $(cont).attr('value');
if(!alldata)
{
alldata = type + ': ' + scope + ' ';
}
else
alldata = alldata + ' ' + type + ': ' + scope + ' ';
};
})
$('#sessions').attr('value',alldata);
}
source
share