且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过单击复选框将Tex tbox值从一个复制到另一个

更新时间:2023-01-07 08:41:15

  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中这样做,

< asp:TextBox ID = txt1 runat = server > < / asp:TextBox >
< asp:TextBox ID = txt2 RUNAT 的pan> = server > < / asp:TextBox >
< asp:CheckBox ID = chk runat = 服务器 文字 = 复制 onclick =
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 =