Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
hi all

i have three text boxes.third text box is read only.Now i want when user enter a value in second text box then a leave event is fired and the total of two text boxes(first and second) is get in third readonly text boxes

actually i want to invoke leave event of third text box and get total using java script .
how to implement using javscript
Posted

You can implement leave event as you are saying with the help of onblur event. Attach onblur event of your second textbox, now when user leaves second textbox, onblur event event will be fired and you can do ehatever you on this event as per your requirement.

see example of onblur event:
Link 1[^]
Link 2[^]
 
Share this answer
 
v2
Comments
Sandeep Mewara 28-Jun-10 2:06am    
Formatted your answer. Removed pre tags and made links look proper
Brij 28-Jun-10 2:32am    
Thanks Sandeep:).
Textbox TextChanged is not firing.even though i gave Autopostback='True"
 
Share this answer
 
you can do like

HTML
<html>
<head>
<script>
function myFunction()
{
var val1=document.getElementById("txtid1");
var val2=document.getElementById("txtid2");
var total="";
if(!isNaN(val1 ) && !isNaN(val2)){
total=val1+val2;
('txtid3').html(total);
}
}
</script>
</head>
<body>

<p>A function is triggered when the user is pressing a key in the input field.</p>

<input type="text" onkeypress="myFunction()">

</body>
</html>
 
Share this answer
 
Comments
CHill60 29-Apr-14 9:21am    
You're nearly 4 years late with this one!

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