Click here to Skip to main content
15,908,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<tr id="America" class="hiddenMenu">
     <td width="1%"</td>
   	 <td align="right">Deposit Type: </td>
   	 <td><select name="Deposit" id="purchase" onChange="purchase(this.value);">
    		<option value="" selected>--Choose Deposit Type--</option>
        	<option value="Contract">Contract</option>
        	<option value="IVR">IVR<option>
   		 	</select>
           
    </td>
   </tr>


<tr>
        <td> </td>
        <td align="right">Purchase Amount: </td>
        <td><input type="text" name="Amount" id="purchase" value="" size="20" maxlength="10"></td>
    </tr>
Posted
Updated 18-Jan-12 17:18pm
v2
Comments
Prasad_Kulkarni 18-Jan-12 23:19pm    
Added pre tags

It is very simple. Use the code below.
Also change the name of the onChange function to something else other than the <select> id itself. In my example, I made the function name as "purchaseFunc()" instead of "Purchase()"

JavaScript
<select name="Deposit" id="purchaseDropDown" onChange="purchaseFunc(this.value);">...
....
<input type="text" name="Amount" id="purchaseTxtBox" value="" size="20" maxlength="10">
....

<script type="text/javascript">

    function purchaseFunc(selectedValue) {
        var txtBoxAmount = document.getElementById("purchaseTxtBox");
        txtBoxAmount.value = selectedValue;
    }
</script>
</select>

EDIT: There seems to be a problem in your code. The Id's of the <select> and textbox seems to be same ("Purchase"). I suggest you change them, and make them different.
The OnChange function name also seems to be "Purchase" itself. Please change that also to something unique for the context.
 
Share this answer
 
v3
Hi,

You can use the below code.

<SELECT NAME ="Deposit"  onChange = CopytoTextBox(this.value)>
......



function CopytoTextBox()
{
len = document.Deposit.length;
i = 0;
chosen = "none";

for (i = 0; i < len; i++)
 {
if (document.Deposit[i].selected)
 {
chosen = document.Deposit[i].value;
 } 
}
document.getElementById("purchase").text=chosen;

}


Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900