Spoiler: Click to Toggle the Spoiler.
CODE
function checkGames(gamesNum)
{
alert("function");
var id2Get = "";
var i = 0;
for (i = 1; i <= (parseInt(gamesNum)); i++)
{
alert("first loop");
id2Get = "h" + i;
document.getElementById(id2Get).style.visibility="visible";
id2Get = "a" + i;
document.getElementById(id2Get).style.visibility="visible";
}
for (i = ((parseInt(gamesNum))+1); i <= 16; i++)
{
alert("second loop");
id2Get = "h" + i;
document.getElementById(id2Get).style.visibility="hidden";
id2Get = "a" + i;
document.getElementById(id2Get).style.visibility="hidden";
}
}
{
alert("function");
var id2Get = "";
var i = 0;
for (i = 1; i <= (parseInt(gamesNum)); i++)
{
alert("first loop");
id2Get = "h" + i;
document.getElementById(id2Get).style.visibility="visible";
id2Get = "a" + i;
document.getElementById(id2Get).style.visibility="visible";
}
for (i = ((parseInt(gamesNum))+1); i <= 16; i++)
{
alert("second loop");
id2Get = "h" + i;
document.getElementById(id2Get).style.visibility="hidden";
id2Get = "a" + i;
document.getElementById(id2Get).style.visibility="hidden";
}
}
[Close]
That's the function with the errors. The function is called with an onchange event on a textbox and is passed the value contained in the textbox. It asks for a number, so that's what will be put into the textbox. I'll eventually set up something to handle other values, but I just want a general framework at the moment. There are two sets of dropdown boxes with ids of h1 through h16 and a1 through a16 respectively.
The alert boxes are for debugging that I was attempting to do.
This function is supposed to make it so when the value in the textbox is changed the webpage will only show that many dropdown boxes. For example, if the user types in '14', the script will show 14 boxes in each set and hide the last 2.
Instead all it does is light up the 'function' alert once, then the 'first loop' alert once.
Can anyone figure out what's wrong?