Link to home
Start Free TrialLog in
Avatar of searchsanjaysharma
searchsanjaysharma

asked on

How to subtract to two asp:textboxes in jquery

I have 2 text boxes in asp.net

<asp:Textbox id="t1" Text="" runat="server"/>
<asp:Textbox id="t2" Text="" runat="server"/>
<asp:Textbox id="t3" Text="" runat="server"/>

t3 is t1-t2

How to do this on value change in t1 and t2 both without postback and with jquery
Avatar of chaitu chaitu
chaitu chaitu
Flag of India image

t3= parseFloat($("#t1")) -parseFloat($("#t2"))
SOLUTION
Avatar of Rajkumar Gs
Rajkumar Gs
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Proculopsis
Proculopsis

Try this jsfiddle.


<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title> - jsFiddle demo by Proculopsis</title>
  
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
  
  <link rel="stylesheet" type="text/css" href="/css/normalize.css">
  <link rel="stylesheet" type="text/css" href="/css/result-light.css">
  
  <style type='text/css'>
    
  </style>
  


<script type='text/javascript'>//<![CDATA[ 
$(function(){
$(".numeric").keyup(function() {
    var t1 = $("#t1").val();
    var t2 = $("#t2").val();
    t1 = parseFloat(t1);
    t2 = parseFloat(t2);
    t1 = isNaN(t1) ? 0 : t1;
    t2 = isNaN(t2) ? 0 : t2;
    $("#t3").val(t1 - t2);
});
});//]]>  

</script>


</head>
<body>
  <input id="t1" class="numeric" />
<input id="t2" class="numeric" />
<input id="t3" />


  
</body>


</html>

Open in new window

Avatar of searchsanjaysharma

ASKER

ok