如何基于下拉列表更改textfiedl值

如何基于下拉列表更改textfiedl值

本文介绍了如何基于下拉列表更改textfiedl值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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>

推荐答案

<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>

您的代码中似乎有问题. < select>的ID和文本框似乎相同(购买").我建议您更改它们,并使其与众不同.
OnChange函数名称本身也似乎是购买".请将其也更改为上下文特有的内容.

</select>

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.


<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.


这篇关于如何基于下拉列表更改textfiedl值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:26