Click to See Complete Forum and Search --> : How to refresh list box after repopulating?


kateyez44
05-21-2003, 10:36 AM
I have 2 list boxes on a page, and I need to change the options displayed in the 2nd list box depending on what option is selected in the 1st list box. The problem I'm having is that I can't figure out how to get the list box to refresh after clearing all of the options out of the list, then adding the new ones. I've tried window.history.go(0), but this just seems to make my page refresh in an infinite loop! :confused:

Here is the code for my 1st list box. In the ONCHANGE event, I call a function called f_lstSatisfactory:

<SELECT NAME = lstSatisfactory ONFOCUS="wStatus(this);" TITLE = "wStatus(this);"
ONCHANGE="f_lstSatisfactory(this);" ONMOUSEOVER="wStatus(this);" ONMOUSEOUT="wStatus('');"
ONBLUR="wStatus('');" TABINDEX = 76 ALT="wStatus(this);">



Here is the code for f_lstSatisfactory:
function f_lstSatisfactory(oField)
{
var oOptions = document.forms[0].lstExplain1;
clearOptions(oOptions);
reOptionExplain1(oField, oOptions);
return;
}


Here is the code for the clearOptions function:
function clearOptions(oOptions)
{
for(var i=oOptions.options.length-1;i>=0;i--)
{
oOptions.options[i] = null;
}
oOptions.selectedIndex = -1;
return;
}


And, finally, here is the code for the reOptionExplain1 function:
function reOptionExplain1(oField, oOptions)
{
var options = new Explain1();

if(oField.value == "Y")
{
for (var i = 0; i <= options.abbrYes.length-1; i++)
{
oOptions.options[i] = new Option(options.optionYes[i], options.abbrYes[i]);
}
oOptions.length = i
}else if(oField.value == "N")
{
for (var j = 0; j <= options.abbrNo.length-1; j++)
{
oOptions.options[i] = new Option(options.optionNo[j], options.abbrNo[j]);
}
oOptions.length = i
}
return;
}


I figure I'm missing something in the reOptionExplain1 function, but cannot figure out what that is. Please help, I'd appreciate it.

khalidali63
05-21-2003, 10:42 AM
can you please post a link to your actual page so that I cna see it breaking..:-)

kateyez44
05-21-2003, 12:21 PM
I can't post a link to the page. It is not being hosted on any public servers. I will add more detail to my description, though, because after re-reading my original post, I realized I left some stuff out.

When I change the value in listBox1, the clearOptions function is called first to clear listBox2. This function seems to work properly, listBox2 is left empty. After the clearOptions function is called, the reOptionExplain1 function is called. The logic in this function also appears to be working correctly. If I put an alert in the for loops, the alerts always appear with the correct values for oOptions.options[i].text. Once this function is finished executing, however, listBox2 is still empty, it is not refreshing with the new option values. This is where I'm at a loss.

I understand that it would be helpful to actually see my page, but is there any advice you can offer based on the behavioral descriptions I've given? Thanks.

khalidali63
05-21-2003, 12:25 PM
in that case is possible for you upload your pages code as a text file here with this thread or as a zip file attachement,because,typically you do not have to worry about this.The moment you make a change to the select box,it should be visible in real time,
since (as you say it) its not happening,I have to see your code in its entirety to see what could be causing this problem.

:D