Click here to Skip to main content
15,887,998 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
Hello Sir ,
I have a two text box(TextBox1,TextBox2) i want the when we enter the values in two text box and move the cursor from TextBox2 then automatically values add and Enter the value in anoter TextBox such TextBox3;
Thanks

Arvind Kumar Singh
Posted
Comments
Sergey Alexandrovich Kryukov 18-Apr-11 5:38am    
Not clear (and too trivial whatever it is). Homework?
Put your code first and explain what's the problem is you need any help.
Only this way can work here, not the other way around.
--SA

Use Javascript.

Try this[^].
 
Share this answer
 
Use jQuery and put this code

$('#id_of_textbox2').keyup(function(event){
  if(event.keyCode == 13){
    $('#id_of_textbox3').val($('#id_of_textbox1').val() + $('#id_of_textbox2').val());
  }
});


Good luck!
 
Share this answer
 
Comments
Arvind_singh 18-Apr-11 5:47am    
Thanks Sir
Tarun.K.S 18-Apr-11 5:59am    
Well accept the answer if it helped you.
You just need to use the LEAVE event

C#
private void textBox2_Leave(object sender, EventArgs e)
     {
         string no1 = textBox1.Text;
         string no2 = textBox2.Text;
         textBox3.Text = AdditAndReturnIt(no1, no2);
     }



The AdditAndReturnIt function is below
C#
public static double? ConvertToDouble(string p_dblToConvert)
     {
         try
         {
             return double.Parse(p_dblToConvert.Trim());
         }
         catch (Exception)
         {
             return null;
         }
     }
     private static string AdditAndReturnIt(string p_no1, string p_no2)
     {
         double? no1conv = ConvertToDouble(p_no1);
         double? no2conv = ConvertToDouble(p_no2);
         if ((no1conv != null) & (no2conv != null))
         {
             return (no1conv + no2conv).ToString();
         }
         return "";
     }
 
Share this answer
 
Comments
Toniyo Jackson 18-Apr-11 5:42am    
Do you have leave event in asp.net?
Rob Branaghan 18-Apr-11 6:03am    
Oops! I suppose there is an onBlur event...
Use JavaScript to grab the value from TextBox1 during the onblur event of that control and pop that value into TextBox2.There are plenty of examples both here and on Google as to how to make that happen.
 
Share this answer
 
I'm not going to give you the exact code, but I will tell you what you need to be looking at. You are going to have to write your code in JavaScript, to handle the fact that the event you are looking at is actually the blur event.
 
Share this answer
 
C#
<html>
<head>
<title>index.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">

<script type="text/javascript">
function getaddedvalue()
{

var a = parseInt(document.getElementById("Text1").value);
var b = parseInt(document.getElementById("Text2").value);
var c=a+b;
var d=document.getElementById("Text3")
d.value=c
}
</script>
</meta></meta></meta></head>
<body>


This is my HTML page.
Text1:<input type="text" name="Text1" id="Text1" placeholder="satyam" />
Text2:<input type="text" name="Text2" id="Text2" placeholder="reddy" />
Text3:<input type="text" id="Text3"  önclick="return getaddedvalue()" />


</body>
</html>
 
Share this answer
 
v2
take textbox3 as html textbox like
C++
<input id="Text1" type="text"  onclick="return getaddedvalue()"/>


Use textbox click event to call javascript function
In javascript call other twotextbox values and add it and display in your desired textbox like

C++
function getaddedvalue() { var a=document.getElementById("TextBox1");
var b=document.getElementById("TextBox2")
var c=a+b;
var d=document.getElementById("Text1")
d.value=c };
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900