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!

populate text field with value from drop down

Status
Not open for further replies.

silkk

Programmer
Jul 14, 2008
16
CZ
Hi guys,

I have triple drop down and I want to use the value from the last selection drop down and to pass it into a text field for further prcedure with PHP.
Here is the code:

<Form name='Categories'>
<p>Country: <Select name='List1' onChange="fillSelect(this.value,Categories.List2)">
<option selected>Make a selection </a></option>

</Select>
</p>
<Select name='List2' onChange="fillSelect(this.value,Categories.List3)">
<option selected>Make a selection</option>
</Select>
<p></p>
<Select name='List3' onChange="getValue(this.value)" onClick= 'showSelected()' >
<option selected >Make a selection</option>

</Select>
</Form>

<Script>


fillSelect('Level1',Categories.List1);
Categories.List2.style.display ="none";
Categories.List3.style.display = "none";



</Script>

 
the scheme is:
1st Array - countries
2nd Array - cities
3rd Array - numbers

What I'm trying to do is to get the selected value from the last drop down and to put it into a text field in another form in the page.
the getValue is taking the value based on the selection of the previous drop down.
 
you should be able to do something like :

document.getElementById("myTextBox").value=document.getElementById('myDropdown')[document.getElementById('myDropdown').selectedIndex].value;

where myTextBox is the ID of the INPUT (textbox) you want to update and myDropdown is the ID of the SELECT (dropdown) you want to grab the value property of the selected option.

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
Perhaps I'm missing the point, but why do you need to do this?

Surely you can simply submit the form to PHP as-is, and read the value of the 3rd drop-down server-side as usual? No need for any jiggery-pokery at all.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi Dan,
there is only one submit button on the page and many forms.I needed to populate a text field for further processing.
The problem is solved already with onChange="document.Categories.showValue.value=this.value" and <input type="text" name="showValue">

I'm newbie in Javascript :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top