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

where did i go wrong?

Status
Not open for further replies.

tsomee

Programmer
May 29, 2007
2
YU
fellow programmers :)
i'm humbly asking for your help (or at least another pair of eyes because i can't see the mistake!) i'm working with some drop-down lists and i'd like the other drop-down to show depending on the selected option from the first drop-down, and also i want it to contain options depending on the choice. here's the code:

<script language="javascript">
function show(elem) {
var tek=elem.options[elem.selectedIndex].value;
elem2=document.getElementById('contractId');
k=0;
shtml="<select>";
for(i=0; i<elem2.length;i++){
if (tek == elem2.options.value){
shtml += "<option>"+ elem2.options.text;
k++;
}
}
shtml="</select>";
if (k>0){
document.getElementById('divId').innerHTML=shtml;
document.getElementById('divId').style.visibility='visible'
}
else{
document.getElementById('divId').style.visibility='hidden'
}
}
</script>

divId is the id of the div where i placed the drop-down (it's in a <td>), contractId is the id of the second drop-down (it's hidden and consists of all available options for the drop-down);
so if the two integer values are equal i'm creating a new drop-down containing the specific options and placing it in the div
of course i'm triggering it with onchange="show(this)"

thanks in advance!! i appreciate it!!! :)

 
Put an alert right here in your code:
Code:
[!]alert(elem2.length);[/!]
for(i=0; i<elem2.length;i++){
 if (tek == elem2.options[i].value){
    shtml += "<option>"+ elem2.options[i].text;
    k++;
 }
}

I think you have to reference that as

elem2.options.length


[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top