通过单击复选框将Tex tbox值从一个复制到另一个 [英] Copy Tex tbox value from one to another by Clicking Checkbox

查看:101
本文介绍了通过单击复选框将Tex tbox值从一个复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我在一个文本框中输入值时使用两个文本框,按下复选框后,文本框值需要复制到其他文本框中如何在Java脚本中使用



你可以帮忙吗?

解决方案

  function  populateText()
{
if document .getElementById (' chechboxid')。已选中)
{
var str = document .getElementById(' textbox1id).value; //在其中输入数据的文本框
document.getElementById('
textbox2id).Value = str;
}
}


将javascrip function 称为复选框 in .aspx页面的pageload方法

pageload()
{

checkboxid.attributes.add( onclick populateText(););
}




你可以在javascript中这样做,

< pre lang =xml> < asp:TextBox ID = txt1 runat = server > < / asp:TextBox >
< asp:TextBox ID = txt2 RUNAT = server > < / asp:TextBox >
< asp:CheckBox ID = chk runat = 服务器 文字 = 复制 onclick < span class =code-keyword> =
copyvalue() / >
< script type = text / javascript >
function copyvalue(){
var txt1 = document.getElementById( <% = txt1.ClientID %> )。value;
document.getElementById(<% = txt2.ClientID %> )。 value = txt1;
}
< / script >





with jquery

 <   asp:TextBox     ID   =  txt1    runat   =  server >  <   / asp:TextBox  >  
< asp:TextBox ID = txt2 runat = server > < / asp:TextBox >
< asp:CheckBox ID = chk runat = server 文本 = 复制 / >
< script src = Scripts / jquery-1.4.1.min.js 类型 = text / javascript > < / script >
< script type = text / javascript >


(# <% = chk.ClientID %> )。change( function(){
var txt1 =


Hi i am using two text box when i enter the value in the one text box and after i pressing the check box the text box value need to copy into other text box how it is possible in Java script

Can u help?

解决方案

function populateText()
{
 if(document.getElementById('chechboxid').checked)
 {
  var str=document.getElementById('textbox1id).value;// textbox in which you enter data
  document.getElementById('textbox2id).Value= str;
}
}


call the javascrip function as attribute to checkbox in pageload method of your .aspx page

 pageload()
 {

 checkboxid.attributes.add("onclick","populateText();");
}


Hi,
You can do like this in javascript,

<asp:TextBox ID="txt1" runat="server"></asp:TextBox>
<asp:TextBox ID="txt2" runat="server"></asp:TextBox>
<asp:CheckBox ID="chk" runat="server" Text="Copy" onclick="copyvalue()"/>
<script type="text/javascript">
function copyvalue() {
    var txt1 = document.getElementById("<%= txt1.ClientID %>").value;
    document.getElementById("<%= txt2.ClientID %>").value = txt1;
}
</script>


OR
with jquery

<asp:TextBox ID="txt1" runat="server"></asp:TextBox>
    <asp:TextBox ID="txt2" runat="server"></asp:TextBox>
    <asp:CheckBox ID="chk" runat="server" Text="Copy"/>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">


("#<%= chk.ClientID %>").change(function () { var txt1 =


这篇关于通过单击复选框将Tex tbox值从一个复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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