Tech
Forums
Jobs
Books
Events
Live
Interviews Prep
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
How to Compute Two TextBox Using Jquery
Abraham Olatubosun
Mar 23 2017 2:05 PM
220
Reply
Dear code masters,
I believe you are all in good health.
I need your Assistance once again, my challenge is as follows:
Let say i have a webform in
ASP.NET
, that have two Textbox's
Txt1
and
Txt2
Txt1 is for previou tempratureand and it is readonly, when the form load previous data from Database is loaded into
Txt1
so the user is expected to input current temprature into
Txt2
we want
Txt2
to validate
Txt1
if it is not a space and if it is greater than or equal to zero. If that happens then
Txt1 = Txt1 + Txt2 else
Txt1 = Txt2.
I use Jqeury as follows:
<script type=
"text/javascript"
src=
"Scripts/jquery-3.1.1.min.js"
></script>
<script type=
"text/javascript"
>
$(
function
() {
$(
'#<%=Text1.ClientID%>'
).blur(
function
sumN1() {
var
T = $(
'#<%=TextBox3.ClientID%>'
).val()
if
(T !=
""
&& T >= 0) {
$(
'#<%=Txt1.ClientID%>'
).val(+$(
'#<%=Txt1.ClientID%>'
).val() + +$(
'#<%=Txt2.ClientID%>'
).val());
}
else
{
$(
'#<%=Txt1.ClientID%>'
).val($(
'#<%=Txt2.ClientID%>'
).val());
}
})
})
</script>
this code works fine, if
Txt1 = 50
from load and the user input 10 in
Txt2
the result in
Txt1 = 60
, but the challange is when the user input the wrong figure 10 instead of 5 and the user change it, it add it up so
Txt1
became 65 but what we want is for
Txt1
to change to 55.
how can we impliment this with the above Jquery.
Thank you all
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
how to make a project
How to extract XFA form field values using javascript