Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 15, 2012 12:25 PM by me_ritz
Member
620 Points
149 Posts
May 15, 2012 11:19 AM|LINK
I have Two Textbox
<asp:TextBox ID="txtBox1" runat="server"Width="60" ReadOnly="true" ></asp:TextBox> <asp:TextBox ID="txtBox2" runat="server" Width="60"></asp:TextBox>
First One is Read Only Containing float Value
My Problem Is When I Enter Some Values In TextBox2 , TexBox1 Value Should SubStract From This And Shows Result.Using JQuery
Star
9337 Points
1447 Posts
May 15, 2012 11:37 AM|LINK
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { var val2 = Number($("#txtBox1").val()); $("#txtBox2").live("keyup", function () { var val1 = Number($(this).val()); if (!isNaN(val1)) { $("#txtBox1").val(val2 - val1); } }); }); </script> ************************** <asp:TextBox ID="txtBox1" runat="server" Width="60" ReadOnly="true" Text="125.50"></asp:TextBox> <asp:TextBox ID="txtBox2" runat="server" Width="60"></asp:TextBox>
Thanks
Contributor
2101 Points
821 Posts
Do you have existing code with an issue or do you want code provided that can do this?
All-Star
34177 Points
5490 Posts
May 15, 2012 11:38 AM|LINK
try this
$("#txtBox2").bind("onchange", Calculate);
function Calculate() {
alert( parseFloat($("#txtBox2").val()) - parseFloat($("#txtBox2").val()));
}
hope this helps...
May 15, 2012 11:50 AM|LINK
My Current JQuery Code
<script type="text/javascript"></script> $(document).ready(function(){ $('#txtBox2').keyup(function () { txtBox2Value = parseFloat($(this).val()); txtBox1Value = $('#txtBox1').val()); if(txtBox1Value != 0 && txtBox1Value >= txtBox2Value) { Result = txtBox1Value - txtBox2Value; $('#lblResult').val(Result); } }); }); </script> ************************** <asp:TextBox ID="txtBox1" runat="server" Width="60" ReadOnly="true" Text="125.50"></asp:TextBox> <asp:TextBox ID="txtBox2" runat="server" Width="60"></asp:TextBox>
i Got Result
But When I Press BackSpace Key It Still SubStract Current Value Not Actual Value
May 15, 2012 12:08 PM|LINK
Try my code...or i modified your code
<script type="text/javascript"></script> $(document).ready(function(){ txtBox1Value = $('#txtBox1').val()); $('#txtBox2').keyup(function () { txtBox2Value = parseFloat($(this).val()); if(txtBox1Value != 0 && txtBox1Value >= txtBox2Value) { Result = txtBox1Value - txtBox2Value; $('#lblResult').val(Result); } }); }); </script> ************************** <asp:TextBox ID="txtBox1" runat="server" Width="60" ReadOnly="true" Text="125.50"></asp:TextBox> <asp:TextBox ID="txtBox2" runat="server" Width="60"></asp:TextBox>
May 15, 2012 12:17 PM|LINK
Example
Suppose TextBox1 Value = 100
When I Enter 50 To TextBox2 ---- I Got TextBox1 Value 50 ---Its Fine
But After That Delete 0 From TextBox2 ie Current Value 5 , It SubStracting From Previous Value That Cause Result Will Be 45
But Result Shoud Be 95
May 15, 2012 12:25 PM|LINK
I understand your problem correctly...try my code...or try the one i modified....and tell if you still face the problem...
Arshad Ashra...
Member
620 Points
149 Posts
JQuery Substraction
May 15, 2012 11:19 AM|LINK
I have Two Textbox
First One is Read Only Containing float Value
My Problem Is When I Enter Some Values In TextBox2 , TexBox1 Value Should SubStract From This And Shows Result.Using JQuery
me_ritz
Star
9337 Points
1447 Posts
Re: JQuery Substraction
May 15, 2012 11:37 AM|LINK
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { var val2 = Number($("#txtBox1").val()); $("#txtBox2").live("keyup", function () { var val1 = Number($(this).val()); if (!isNaN(val1)) { $("#txtBox1").val(val2 - val1); } }); }); </script> ************************** <asp:TextBox ID="txtBox1" runat="server" Width="60" ReadOnly="true" Text="125.50"></asp:TextBox> <asp:TextBox ID="txtBox2" runat="server" Width="60"></asp:TextBox>Thanks
breath2k
Contributor
2101 Points
821 Posts
Re: JQuery Substraction
May 15, 2012 11:37 AM|LINK
Do you have existing code with an issue or do you want code provided that can do this?
kedarrkulkar...
All-Star
34177 Points
5490 Posts
Re: JQuery Substraction
May 15, 2012 11:38 AM|LINK
try this
$("#txtBox2").bind("onchange", Calculate);
function Calculate() {
alert( parseFloat($("#txtBox2").val()) - parseFloat($("#txtBox2").val()));
}
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
Arshad Ashra...
Member
620 Points
149 Posts
Re: JQuery Substraction
May 15, 2012 11:50 AM|LINK
My Current JQuery Code
<script type="text/javascript"></script> $(document).ready(function(){ $('#txtBox2').keyup(function () { txtBox2Value = parseFloat($(this).val()); txtBox1Value = $('#txtBox1').val()); if(txtBox1Value != 0 && txtBox1Value >= txtBox2Value) { Result = txtBox1Value - txtBox2Value; $('#lblResult').val(Result); } }); }); </script> ************************** <asp:TextBox ID="txtBox1" runat="server" Width="60" ReadOnly="true" Text="125.50"></asp:TextBox> <asp:TextBox ID="txtBox2" runat="server" Width="60"></asp:TextBox>i Got Result
But When I Press BackSpace Key It Still SubStract Current Value Not Actual Value
me_ritz
Star
9337 Points
1447 Posts
Re: JQuery Substraction
May 15, 2012 12:08 PM|LINK
Try my code...or i modified your code
<script type="text/javascript"></script> $(document).ready(function(){ txtBox1Value = $('#txtBox1').val()); $('#txtBox2').keyup(function () { txtBox2Value = parseFloat($(this).val()); if(txtBox1Value != 0 && txtBox1Value >= txtBox2Value) { Result = txtBox1Value - txtBox2Value; $('#lblResult').val(Result); } }); }); </script> ************************** <asp:TextBox ID="txtBox1" runat="server" Width="60" ReadOnly="true" Text="125.50"></asp:TextBox> <asp:TextBox ID="txtBox2" runat="server" Width="60"></asp:TextBox>Arshad Ashra...
Member
620 Points
149 Posts
Re: JQuery Substraction
May 15, 2012 12:17 PM|LINK
Example
Suppose TextBox1 Value = 100
When I Enter 50 To TextBox2 ---- I Got TextBox1 Value 50 ---Its Fine
But After That Delete 0 From TextBox2 ie Current Value 5 , It SubStracting From Previous Value That Cause Result Will Be 45
But Result Shoud Be 95
me_ritz
Star
9337 Points
1447 Posts
Re: JQuery Substraction
May 15, 2012 12:25 PM|LINK
I understand your problem correctly...try my code...or try the one i modified....and tell if you still face the problem...
Thanks