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
464 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
Comment Utility
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
Comment Utility
Hi.  I see steps 2. and 3.  Is there supposed to be a step 1. ?
0
 
LVL 1

Author Comment

by:megnin
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now