Pass value from one textbox to anothet

Posted on 2009-04-27
Last Modified: 2012-05-06
Hello Guys! I have a combo box which has two values namely Allowence and Accommodation. When Allowence is selected, the focus is shifted to a text box to enter the value. Once the value is entered, I want that value to be in another text box. How can I do that and under which control should I write the code. Something like this.
txtemphraallowence = txtemphracost
Question by:preethamonline
    LVL 2

    Expert Comment

    i'd use

    txtemphraallowence.text = txtemphracost.text

    put this on the textchangeed event of txtemphracost. If you're using webforms make sure autopostback is set to true.
    LVL 9

    Accepted Solution

    i would do it with javascript:
    on page_load attach onblur attribute on textbox where you want to copy from and attribute value is a javascript statement to copy the entered value.
    No postbacks required...

                    String.Format("javascript:document.getElementById('{0}').value=document.getElementById('{1}').value;", txt1.ClientID, txt2.ClientID));

    Open in new window

    LVL 26

    Expert Comment

    by:Anurag Thakur
    i will ask a question before i suggest a solution
    why - what is the need to copy the text from one text box to another?

    Author Comment

    Well ragi, i have a drop down list with 2 values. One is allowence and the other is accomodation.
    I have 2 text boxes. One for allowence and the other called ctc.
    So when a value is entered in allowence text box i also want it to appear in the ctc box, so that it helps calculating the CTC (Cost to company) of the employee.

    I hope its not confusing. I have attached a sample screenshot of what i'm trying to achieve.
    LVL 26

    Expert Comment

    by:Anurag Thakur
    the solution provided by tetorvik should do the trick for you

    Author Comment

    Thanks guys.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    730 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

    15 Experts available now in Live!

    Get 1:1 Help Now