如何基于下拉列表更改textfiedl值 [英] how to change the textfiedl value based on drop down list

查看:100
本文介绍了如何基于下拉列表更改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>

推荐答案

这很简单.使用下面的代码.
还要将onChange函数的名称更改为< select>之外的其他名称. ID本身.在我的示例中,我将函数名称命名为"purchaseFunc()",而不是"Purchase()"

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()"

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


您好,

您可以使用以下代码.

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.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆