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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dependent drop-downs

Status
Not open for further replies.

ptichka

Programmer
May 28, 2002
19
US
Hello everybody,

I need help.
I have two drop down lists (each populated by it's own query). If the user selects an option in the first one, that should then effect the output of the list in the second drop-down. But I need all this to work with out my page being reloaded every time.

Does anyone have any suggestions for me?

Thanks in advance for any input.
 
This might put you on the right track.


<body>
<table width = &quot;80%&quot;><tr>
<td width = &quot;50%&quot; valign = 'top'>
<span id = &quot;chooseLanguage&quot;>Choose language:</span>
<br />
<br />
<select name = &quot;language&quot; onChange = &quot;changeAllLang()&quot;>
<option value = &quot;en&quot;>English</option>
<option value = &quot;fr&quot;>French</option>
<option value = &quot;de&quot;>German</option>
</select>
<br />
<br />
</td>
<td valign = 'top'>
<span id = &quot;chooseColour&quot;>Choose colour:</span>
<br />
<br />
<select name = &quot;colours&quot; onChange = &quot;changeAllCol()&quot;>
<option value = &quot;red&quot;>Black</option>
<option value = &quot;red&quot;>Red</option>
<option value = &quot;green&quot;>Green</option>
<option value = &quot;blue&quot;>Blue</option>
<option value = &quot;yellow&quot;>Yellow</option>
</select>
</td>
</tr></table>

<script language = &quot;JavaScript&quot;>

noLangs = colours.length;
var cL = new Array(&quot;Choose language:&quot;, &quot;Choisir la langue:&quot;, &quot;Sprache waehlen:&quot;);
var cC = new Array(&quot;Choose language:&quot;, &quot;Choisir la couleur:&quot;, &quot;Farbe waehlen:&quot;);

var clE = new Array(&quot;Black&quot;, &quot;Red&quot;, &quot;Green&quot;, &quot;Blue&quot;, &quot;Yellow&quot;);
var clF = new Array(&quot;Noir&quot;, &quot;Rouge&quot;, &quot;Vert&quot;, &quot;Bleu&quot;, &quot;Jaune&quot;);
var clG = new Array(&quot;Schwarz&quot;, &quot;Rot&quot;, &quot;Gruen&quot;, &quot;Blau&quot;, &quot;Gelb&quot;);

function changeAllLang()
{
which = language.selectedIndex;
chooseLanguage.innerText = cL[which];
chooseColour.innerText = cC[which];

for(i = 0;i < noLangs;i++)
// this has to be always &quot;0&quot;, as the first element is always removed AND replaced automatically
colours.remove(0);

for(i = 0;i < noLangs;i++)
{
newOpt = document.createElement(&quot;OPTION&quot;);

// Here we can could have used associative arrays to shorten the code
if(which == 0)
{
newOpt.text = clE;
newOpt.value = clE.toLowerCase();
}
else if(which == 1)
{
newOpt.text = clF;
newOpt.value = clF.toLowerCase();
}
else
{
newOpt.text = clG;
newOpt.value = clG.toLowerCase();
}
colours.add(newOpt, i);
}
}

function changeAllCol()
{
which = colours.selectedIndex;

chooseColour.style.color = clE[which];
chooseLanguage.style.color = clE[which];
language.style.color = clE[which];
colours.style.color = clE[which];
}
</script>
</body>


vlad
 
I am pretty new at JavaScript, so this might be easy stuff that I just don't know.
How do I user the results of my 2 queries to get my lists?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top