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

how to populate a textbox based on one dropdown selection

Status
Not open for further replies.

dsda7

Programmer
Joined
Jul 28, 2006
Messages
1
Location
US
Hi Everyone,

we have 2 dropdowns and a textbox. choice made in dropdown1 populates dropdown2. how do we populate the value from dropdown2 to a textbox, when a dropdown2 has only one option. we have used the onchange functions in dropdown1 and 2

below is the code we have, which works for dropdown2 with multiple options.

var groups=document.form1.dropdown1.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group=new Array()

group[0][0]=new Option("Please Select one of the options")

group[1][0]=new Option("1 - Agent did not complete all necessary requirements for a 2.")

group[2][0]=new Option("2 - Agent omitted salutation from required Greeting.")


group[3][0]=new Option("3 - Agent added salutation to required Greeting.")
group[3][1]=new Option("3 - Agent added salutation to required Greeting111.")
group[3][2]=new Option("3 - Agent added salutation to required Greeting222.")

var temp=document.form1.dropdown2

function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options=new Option(group[x].text,group[x].value)
}
temp.options[0].selected=true
}



function showtext(){
var txt
txt=document.form1.dropdown2.options[document.form1.dropdown2.selectedIndex].text
document.form1.textbox.value=txt
}

Any help is appreciated..

DSDA7

 
You have to make the first process a 2 step process:

when someone changes something in the first dropdown then:
1) The elements in the 2nd dropdown are populated
2) The textbox is autopopulated to the first element in the 2nd dropdown.

That way if only one element is available, it's populated as soon as something changes in dropdown #1. Additionally, if there were multiple options in dropdown #2 but the user wanted to select the first option, it would be selected for them initially.

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top