Solved

How to copy contents of one text box to another text box inside a FormView if CheckBox is checked using JavaScript

Posted on 2011-02-21
3
471 Views
Last Modified: 2012-06-27
Inside <asp:FormView ID="FormView1" FormView1, in the <EditItemTemplate>
I have two TextBoxes:
<table><td><asp:TextBox ID="SSNTextBox" runat="server" Text='<%# Bind("SSN") %>'/>
... and ...
<asp:TextBox ID="VerifySSN" runat="server" Text="" />

Also in the EditItemTemplate there's a CheckBox:
<asp:CheckBox ID="cbVerify" runat="server" Checked='<%# Bind("Verify") %>' />

When the page loads, if the CheckBox is checked I need to put the contents of TextBox "SSNTextBox" into TextBox "VerifySSN" with JavaScript

Please show me how to do that.  Thank you!!!
0
Comment
Question by:megnin
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
kirankumar_goura earned 500 total points
ID: 34944283
2.In the head section add the following code
<script language = "javascript" type= "text/javascript">
 function ClickSample()
 {
     var txtSSNValue = document.getElementById('<%=SSNTextBox.ClientID %>').value;
     var txtVerifySSN = document.getElementById('<%=VerifySSN.ClientID %>');
     txtVerifySSN.value = txtSSNValue;
  }
</script>3.On the page load add the following.

cbVerify.Attributes.Add("onclick", "return ClickSample();");

0
 
LVL 1

Author Comment

by:megnin
ID: 34945690
Hi.  I see steps 2. and 3.  Is there supposed to be a step 1. ?
0
 
LVL 1

Author Comment

by:megnin
ID: 34945730
Oh, I don't want the text copied from one textbox to the other WHEN the checkbox is checked.  I only want to TEST the checkbox on PageLoad, and IF it is checked copy the contents of the first textbox to the second text box.  If the check box is not checked I don't want to do anything.

I coud do it about like this in VB, but I want to do it client side.

On PageLoad
   If cbVerify.Checked = true Then
       VerifySSN.Text = SSNTextBox.Text
   End If

Thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question