如何自动将下拉列表中所选选项的值复制到文本中.使用jQuery [英] How to automatically copy up the value of selected option of dropdown list into a text. Using jquery

查看:84
本文介绍了如何自动将下拉列表中所选选项的值复制到文本中.使用jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
基于所选选项值的表单输入值

Possible Duplicate:
Form input value based on option value selected

我有一个下拉列表.我希望每当我从下拉列表中选择一个值时,所选值就会自动复制到相同格式的文本框中.我想使用jQuery,而不仅仅是其他简单的Javascript方法.

I have a dropdown list. I want that whenever I select a value from the dropdown, the selected value is automatically copied into a text box in the same form. I would like to make use of jQuery and not simply other, plain Javascript methods.

该表格的代码为:

<s:form action="okadddqs" method="post" cssClass="text">
    <s:select label="Correct Option :" 
        id="opc"
        name="opc"       
        list="#@java.util.LinkedHashMap@{'One':'One', 'Two':'Two','Three':'Three','Four':'Four','Five':'Five'}"/>
    <s:textfield label="Choosed Option" id="cname" name="cname"/>
    <s:submit value="Submit now"/>

我将cname填充为选定的opc值.我该如何实现?

I wnat cname to be filled automatically with the selected value of opc. How do I implement this?

推荐答案

$(document).ready(function(){
    $("#opc").change(function(){
        $("#cname").val($(this).find("option:selected").text());
    });

});

演示

这篇关于如何自动将下拉列表中所选选项的值复制到文本中.使用jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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