Right so the question maybe doesn't illustrate what I'm trying to say but here's what I'm trying to achieve. I have got 6 text boxes on a page each of which contains a number between 0 and 500 (there is no limit but I'm not expecting the number to be higher than this). This number is dependent on a calculation elsewhere, but is irrelevant for this question so I've left it out. Anyway, what I'm trying to do is;
Run through a loop and assign a new text box scoreone, scoretwo etc in the code below an index between 1 and 10 based on the size of the values in indexone, indextwo etc.
So for example if indexone contains 15, the textbox scoreone will be populated with 0. Now this works fine, but only for one textbox, as I have six, I'm not sure how to do this for all of them (i.e. one after the other). I'm using JavaScript and jQuery...
HTML:
<input type="text" disabled="disabled" value="20" id="indexone" />
<input type="text" disabled="disabled" value="0" id="scoreone" /><br>
<input type="text" disabled="disabled" value="60" id="indextwo" />
<input type="text" disabled="disabled" value="0" id="scoretwo" /><br>
<input type="text" disabled="disabled" value="100" id="indexthree"/>
<input type="text" disabled="disabled" value="0" id="scorethree" /><br>
<input type="text" disabled="disabled" value="160" id="indexfour"/>
<input type="text" disabled="disabled" value="0" id="scorefoure" /><br>
<input type="text" disabled="disabled" value="180" id="indexfive"/>
<input type="text" disabled="disabled" value="0" id="scorefive" /><br>
<input type="text" disabled="disabled" value="210" id="indexsix"/>
<input type="text" disabled="disabled" value="0" id="scoresix" /><br>
JS:
var indexArray = [indexone, indextwo, indexthree, indexfour, indexfive, indexsix];
for (var i = 0; i < indexArray.length; i++) {
if ((indexArray[i] >= 0) && (indexArray[i] < 25)) {
scoreone = parseInt(1);
$('#scoreone').val(scoreone);
}
else if ((indexArray[i] >= 25) && (indexArray[i] < 50)) {
scoreone = parseInt(2);
$('#scoreone').val(scoreone);
}
else if ((indexArray[i] >= 50) && (indexArray[i] < 75)) {
scoreone = parseInt(3);
$('#scoreone').val(scoreone);
}
else if ((indexArray[i] >= 75) && (indexArray[i] < 100)) {
scoreone = parseInt(4);
$('#scoreone').val(scoreone);
}
else if ((indexArray[i] >= 100) && (indexArray[i] < 125)) {
scoreone = parseInt(5);
$('#scoreone').val(scoreone);
}
else if ((indexArray[i] >= 125) && (indexArray[i] < 150)) {
scoreone = parseInt(6);
$('#scoreone').val(scoreone);
}
else if ((indexArray[i] >= 150) && (indexArray[i] < 175)) {
scoreone = parseInt(7);
$('#scoreone').val(scoreone);
}
else if ((indexArray[i] >= 175) && (indexArray[i] < 200)) {
scoreone = parseInt(8);
$('#scoreone').val(scoreone);
}
else if ((indexArray[i] >= 200) && (indexArray[i] <= 225)) {
scoreone = parseInt(9);
$('#scoreone').val(scoreone);
}
else if (indexArray[i] > 225) {
scoreone = parseInt(10);
$('#scoreone').val(scoreone);
}
}
I've put what I'm trying to do in a fiddle here too...
scoreoneusescore1and make the name by appendingscore+iwhereiis the loop iteratorparseInt(6)? 6 is already an int.