Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
I have two textboxes.I want to change 2nd textbox value according to whatever i entered in 1st textbox..means suppose i enter 5 in first text and then value 50 should come in 2nd textbox. plz help me?
Posted 16-Feb-13 1:09am
Comments
Nilesh Patil Kolhapur at 16-Feb-13 7:49am
   
you should try Sandeep Mewara's answer
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You need to work on TextBox1_TextChanged event.
 
protected void TextBox1_TextChanged(object sender,EventArgs e)
{
int example=Convert.ToInt32(Textbox1.Text*10);
Textbox2.Text=Convert.ToString(example);
}
 
Change the AutoPostBack property As true for TextBox1.
 

It will display.
TextBox1 TextBox2
 
1----------->10
2----------->20
3-----------> 30
4-----------> 40
5-----------> 50
 

Hope it will help you.
  Permalink  
Comments
Sandeep Mewara at 16-Feb-13 8:22am
   
Why to do all these when one can achieve it on client side. If OP was really asking for Server side code, then you have my vote too. But, in that case, OP is really a beginner and should read some book before starting to code.
Gunjan Bhasin at 16-Feb-13 13:35pm
   
Whats wrong in the code?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Last time, please try such small things by yourself instead of asking questions here. You need to learn and make some effort.
 
Steps for your thing:
1. Define a onblur or onfocusout event for the textbox1 (if server control then add through attributes)
2. Define the related method in JavaScript
3. In this method, get the value of textbox1 and then based on it set the value in textbox2
 
You might need to know:
How to access textbox value in JS:
document.getElementById("textbox1").value
How to add attribute via code:
textbox1.Attributes.Add("onblur","javascript: GetT1ValueAndSetT2(this);");
 
So overall,
HTML:
<asp:TextBox ID="txtValue1" runat="server" ></asp:TextBox>
<asp:TextBox ID="txtValue2" runat="server"  ></asp:TextBox>
 
and Javascript
<script type="text/javascript">
  function GetT1ValueAndSetT2(txtValue1)
  {
     document.getElementById("txtValue2").value=parseFloat(txtValue1.value,10)*5;
  }
 
</script>
Try now.
  Permalink  
v4
Comments
Nilesh Patil Kolhapur at 16-Feb-13 8:11am
   
sir sorry but i tried like <asp:TextBox ID="txtValue2" runat="server" onblur="GetT1ValueAndSetT2(this)" > and its working fine sorry if i am wrong....
Sandeep Mewara at 16-Feb-13 8:19am
   
Is it? onblur event on server textbox? From when? If it's an input type textbox, it would but with ASP.NET Textbox control? BTW, it's ok. You tried to help more, it's just that the addition didn't looked right to me. Keep sharing others and keep good work up. :)
Nilesh Patil Kolhapur at 23-Feb-13 4:25am
   
Yes sir u can try. just write client side event like onkeypress directly in server side control script. try this
Shahriar Iqbal Chowdhury/Galib at 16-Feb-13 8:39am
   
good answer @sandeep, plain and simple.
Sandeep Mewara at 16-Feb-13 8:41am
   
Thanks.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,
 
You can use jquery to solve the issue. Try this solution below,
<script  type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
 
        $("input[type='text']:eq(0)").keyup(function () {
            var txtVal = $("input[type='text']:eq(0)").val();
            var calculated = parseInt(txtVal) * 10;
            $("input[type='text']:eq(1)").val(calculated);
 
        });
    });
</script>
And here is your TextBox's
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
 
Hope this will help.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 685
1 Manas Bhardwaj 380
2 OriginalGriff 344
3 Abhinav S 293
4 Sampath Lokuge 245
0 Sergey Alexandrovich Kryukov 7,967
1 OriginalGriff 4,332
2 Peter Leow 3,699
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 16 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid