Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Listbox

Status
Not open for further replies.

wbj433s

Programmer
Aug 6, 2001
3
US
Hi All -
I'm trying to get the value of one listbox to dynamically repopulate another. I've read the FAQ on dynamic listboxes by iza, and it would seem to be exactly what I want to do. Here's the problem: When I select an option from the first listbox, it adds new options to the second listbox, but the text is not displayed! In other words, if my second list box gets all of its options deleted, and then gets three new ones added, then the listbox drops down and shows three empty rows! Any thoughts? It almost seems like the screen isn't repainting correctly??? Here's an example of my source:

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title>Listbox Test</title>
<script language=&quot;JavaScript&quot;>
function FirstChoice_Change()
{
var oOption = document.createElement(&quot;OPTION&quot;);
oSecond.text = oFirst.text;
oSecond.value = oFirst.value;
oSecond.options.add(oOption);
return true;
}

function SecondChoice_Change()
{
var oOption = oSecond.value;
MyText.value = oOption;
return true;
}
</script>
</head>
<body>
<select id=&quot;oFirst&quot; name=&quot;FirstChoice&quot; onchange=&quot;FirstChoice_Change()&quot;>
<option value=0>- Pick a value -
<option value=1>One
<option value=2>Two
<option value=3>Three
</select>
<select id=&quot;oSecond&quot; name=&quot;SecondChoice&quot; onchange=&quot;SecondChoice_Change()&quot;>
<option value=0>- Pick another value -
</select>
<input type=&quot;text&quot; id=&quot;MyText&quot;>
</body>
</html>

 
Nevermind :) I figured it out. Stupid newbie trick...hehe

For those that may be stumbling as I am, the critial part that was causing me difficulty is in the function FirstChoice_Change(). The two lines that say:

oSecond.text = oFirst.text;
oSecond.value = oFirst.value;

should be replaced with these three:
var oSelected = oFirst.options[index];
oOption.text = oSelected.text;
oOption.value = oFirst.value;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top