Hi one and all,
I am using C#.net language in asp.net framework using visual studio 2008. I have one checkbox as input control and two textboxes named textbox1 and textbox2 as asp controls. First the client needs to type something in textbox1 and after that the client needs to check the input checkbox. Then the text in textbox2 should be as same as that of textbox1. How to write javascript for this. The following did not work:
I have given onclick=display() near input control of checkbox:
I have written javascript as follows:
document.getElementById("textbox1").innertext = document.getElementById("textbox2").innertext .
Please help me thanx in advance

Recommended Answers

All 6 Replies

Use value instead of innertext.

Thanx for the reply but it did not work

did you use master page?

Give this a shot:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SignUp.aspx.cs" Inherits="daniweb.asp.SignUp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
	<script type="text/javascript">
		function copyValues() {
			document.getElementById("<%=TextBox2.ClientID%>").value = document.getElementById("<%=TextBox1.ClientID%>").value;
	}
	</script>

    <form id="form1" runat="server">
    <div>
    	<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    	<br />
    	<asp:CheckBox ID="CheckBox1" runat="server" Text="Copy" />
    	<br />
    	<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

Thanx mail2saion for ur co-operation. I have used master pages in my project. But I did not write the code in the master page. I have written the following code in aspx page and got the correct output.

if (document.getElementById("<%=textbox1.ClientID%>").value!="")
 document.getElementById("<%=textbox2.ClientID%>").value = document.getElementById("<%=textbox1.ClientID%>").value

Thanx sknake for your reply. I already got the output. Anywayz my code is as same as yours

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.