Need JScript code to put same ASP.net Textbox value in another Textbox (same page / same form)

Enflow
Enflow used Ask the Experts™
on
Need simple JavaScript Solution to Put Same ASP.net text box text values into another ASP.net textbox on the same form and same page...

I have this working in asp.net runat with vb.net code and onkeypress call code BUT the postback re-positioning is irritating including trying to suppress it with maintain...

JScript should cause no post back i assume and be quite easy ?

<%@ Page Language="VB" AutoEventWireup="false" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data"%>\
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.data.OleDb" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>

<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

    Private Sub MyTextBox_TextChanged(sender As Object, e As EventArgs) Handles MyTextBox.TextChanged
        AddTextBox.Text = MyTextBox.Text
    End Sub
</script>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body> 
  <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="MyTextBox" runat="server" onkeypress="AddTextBox_TextChanged" AutoPostBack="true"></asp:TextBox>
        <asp:TextBox ID="AddTextBox" runat="server" Enabled="False" ReadOnly="True"></asp:TextBox>
    </div>    
  </form>
</body>
</html>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chief Technology Ninja
Distinguished Expert 2018
Commented:
Hi Enflow,

Assuming you are not using Jquery

<script>
function copyValues()
{
document.getElementById("TARGET TEXTBOX's ID").value = document.getElementById("SOURCE TEXTBOX's ID").value;
}
</script>

Open in new window


Regards,
Chinmay.

Author

Commented:
Working Now ... Thanks...

Function JS code:

function matchSigs() {document.getElementById("AutoSN_1").value = document.getElementById("SN_1").value;}

Here is Source ASP.NET Textbox

<asp:TextBox ID="SN_1" runat="server" Height="25px" Width="340px" Wrap="False" BackColor="#EAF4FF" Font-Size="Large" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" ToolTip="Head of Household Types In Their Full Name Signature Here" onchange"javascript;matchSigs();"></asp:TextBox>

Here is TARGET ASP.NET Textbox

<asp:TextBox ID="AutoSN_1" runat="server" Height="25px" Width="270px" Wrap="False" BackColor="#F2F2F2" Font-Size="Large" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" ToolTip="Applicant's Signature Goes Here Automatically" Enabled="False" ReadOnly="True"></asp:TextBox>

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial