Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

two fields on webpage, want same info displayed in second field

Status
Not open for further replies.

sharonchapman7

Programmer
Aug 31, 2011
45
US
Hi,
I have two fields on my webpage that I want to display the same data in. The first field is a textbox named txtFirstName. I want the user to input his first name and then I want the first name to display automatically in the next field. I want the information in the second field to display before the user hits the submit button. I am using ASP.net, runat="server" I am coding in html and VB. Can someone please tell me how I would do this?

Thank you
Sharon
 
You would have to use client side script ie Javascript to do this. You would have to do it when an action occurs, such as a key press if you want it to happen on each character entered, or when the user leaves the first textbox. If that is the case you can use onblur(when the first textbox looses focus)
 
My problem is that I'm using Visual Basic as my language. Is there a way to do this in VB script?

Thanks for your quick reply.

Sharon
 
hi,
I have attached my code so that you can see what I'm dealing with. the first file, Default_aspx.txt is the html page and the second file Default_aspx_vb.txt is my visual basic code that uploads the data input into a SQL Server database.

Thanks for your help.
Sharon
 
 http://www.mediafire.com/?s7pksc6x388pqsp,4k3pj21fvm52a44
You cannot do this with vb.net code unless you do a post back to the server.
 
Thanks, someone gave me this code and it works.
<script language="javascript">
02 var copy_field = function(id1,id2)
03 {
04 document.getElementById(id2).value =
05 document.getElementById(id1).value;
06 };
07 if( !window.onload )
08 {
09 window.onload = function() {
10 document.getElementById('txtFirstname').onchange=
11 function(){copy_field('txtFirstname','txtReqFirstname');};
12 };
13 }
14 else
15 {
16 var f = window.onload;
17 window.onload = function()
18 {
19 f.call(window);
20 document.getElementById('txtFirstname').onchange=
21 function(){copy_field('txtFirstname','txtReqFirstname');};
22 };
23 }
24 </script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top