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
476 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

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-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…
Suggested Courses

635 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