Hey, I'm writing some code to display a rank in a select box. I have to make it so the same number isn't picked twice. My code works the first time, but I have to change the onchange (ironic I know) to have the new rank as origRank. The code is like this:
Now the alert boxes show, "so far" then the HTML for each select box that changes for thew outerHTML alerts. The HTML looks fine; displays like this:
where the # is the ID from the DB (MS ACCESS) and the 1 is the NEW Rank. But it refuses to handle the event again. I tried both setting it with the setAttribute('onchange',.... and just flat out thisRank.onchange = 'changeRank'... as you can see, but it won't run on the second instance of the event call. It WILL run on the second change if I don't change the 'onchange' value, but it messes up because the parameter for origRank is still coming from the original DB value i.e. I change the rank1 from one to six, everything looks ok, but origRank for rank1 is still 1 and if I change it again, it messes everything up. I know I can do a Jscript submit after the onchange event, but the form submits very very slow cause the DB is Access and has to update many records, so that is not an option. I also tried putting this.option[this.selectedIndex].value inside the onchange call, but it updates before the rest, and i need the origRank that was there before the last change, unless I rethink my whole logic, which I don't feel like doing right now.
Anyone know how I can change the onchange value in the select boxes whose rank have been changed and have it still handle the event?
Thanks,
Bob
Code:
function changeRank(changedID, origRank)
{ alert('so far');
var rankDropDown = document.getElementsByTagName("select");
var thisRank = document.getElementById(changedID);
for (var i = 0; i < rankDropDown.length; i++)
{
if (origRank > thisRank.options[thisRank.options.selectedIndex].value)
{
if (rankDropDown[i].name != thisRank.name)
{
if (rankDropDown[i].options[rankDropDown[i].options.selectedIndex].value < origRank && rankDropDown[i].options[rankDropDown[i].options.selectedIndex].value >= thisRank.options[thisRank.options.selectedIndex].value)
{
rankDropDown[i].options.selectedIndex = rankDropDown[i].options.selectedIndex + 1;
rankDropDown[i].setAttribute('onchange','changeRank(\'' + rankDropDown[i].name + '\',' + rankDropDown[i].options[rankDropDown[i].options.selectedIndex].value + ');');
alert(rankDropDown[i].outerHTML);
}
}
}
else
{
if (rankDropDown[i].name != thisRank.name && rankDropDown[i].options[rankDropDown[i].options.selectedIndex].value >= origRank)
{
if (thisRank.options[thisRank.options.selectedIndex].value >= rankDropDown[i].options[rankDropDown[i].options.selectedIndex].value)
{
rankDropDown[i].options.selectedIndex = rankDropDown[i].options.selectedIndex - 1;
rankDropDown[i].setAttribute('onchange','changeRank(\'' + rankDropDown[i].name + '\',' + rankDropDown[i].options[rankDropDown[i].options.selectedIndex].value + ');');
alert(rankDropDown[i].outerHTML);
}
}
}
}
thisRank.onchange = '"changeRank(\'' + changedID + '\',' + thisRank.options[thisRank.options.selectedIndex].value + ');"';
alert(thisRank.outerHTML);
}
Now the alert boxes show, "so far" then the HTML for each select box that changes for thew outerHTML alerts. The HTML looks fine; displays like this:
Code:
<select name="rank#" id="rank#" onchange="changeRank('rank#', 1);"><option value="1" selected>1</option>....
Anyone know how I can change the onchange value in the select boxes whose rank have been changed and have it still handle the event?
Thanks,
Bob