Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two textboxes.

I will calculate the values of two text box inputs then when I click on 3rd text box then the calculated value will be shown on the 3rd text box.

Can anyone please tell me how to do that?

You can only give me solution about that click event.
Posted
Updated 19-Oct-10 21:43pm
v2
Comments
Dalek Dave 20-Oct-10 3:43am    
Edited for Readability.

You need to use Js onFocus Event.

Suppose there are three textbox named,

TextBox1,TextBox2,TextBox3

Then write onFocus Event on TextBox3 Like.

<asp:textbox id="TextBox3" runat="Server" onfocus="javascript:focused(this)" xmlns:asp="#unknown" />


JavaScript
function focused(txt3)
{
var result = document.getElementById("TextBox1").value * document.getElementById("TextBox2").value;
            txt3.value = result;

}


[Additional answer]
You could use THIS[^]
[/additional answer] to count date difference.

and your'e done.

Please vote and Accept Answer if it Helped.
 
Share this answer
 
v2
Comments
sazib 20-Oct-10 5:16am    
Thanks for your reply.You solution works well for any values.But I have to work with dates. I've two text box startdate and enddate. I will input two date into two text box one is txtBoxStartDate and another one txtBoxEndDate. I want to show the duration of these two dates after I click on duration text box. Can you please tell me the whole procedure using javascript or jquery? I know the calculation in C# but as I'm a beginner of javascript,so I need your help.
Hiren solanki 20-Oct-10 5:19am    
duration in minutes,seconds,hours... ???
sazib 20-Oct-10 5:48am    
I need only days.nothing else.
Hiren solanki 20-Oct-10 5:53am    
see my additional answer.
use the enter event of the textbox ..

use the below code

<pre lang="cs">private void textBox3_Enter(object sender, EventArgs e)
       {
           textBox3.Text = Convert.ToString (Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text));
       }

 
Share this answer
 
v3
Comments
Hiren solanki 20-Oct-10 3:05am    
Question is from asp.net, and it doesn't support _enter event.
Rajesh Anuhya 20-Oct-10 3:06am    
ohhh.., am sorry i just confused,,
sazib 20-Oct-10 4:09am    
Thanks for your ans. It's not working the way I need to.I've two text box startdate and enddate. I want to show the duration of these two dates after I click on duration text box. I know the calculation but I don't know how to automatically put the duration value after just a single click on duration textbox.
Rajesh Anuhya 20-Oct-10 6:04am    
hi "madhukk" .., why u edited my answers as "OnTextChanged" instead of "Enter" event(which i write).., is there any specific reason?????????
do it on blur like it drag a button and on button click write ur code:


textBox3.Text = Convert.ToString (Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text));

and
onload event of page write this

protected void Page_Load(object sender, EventArgs e)
{
Button1.Visible = false;
string handler = ClientScript.GetPostBackEventReference(this.Button1, "");
TextBox2.Attributes.Add("onblur", handler);
}
 
Share this answer
 
v2
Comments
Mohd Wasif 20-Oct-10 6:05am    
also add EnableEventValidation="false" in design of page
http://www.codeproject.com/KB/cs/TextBox_subclassing.aspx[^] try this link...............otherwise u can use javascript to implement this............
 
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