How Compare four Textbox value w with another Sum Value using Javascript

Posted by Cpatil1000 under ASP.NET on 5/26/2014 | Points: 10 | Views : 748 | Status : [Member] | Replies : 0
I have four Textbox and I am compare with another values. My Textbox is like name tbTargetedNotWQStarted, tbTargetedNonWQStage1, tbTargetedNonWQStage2, tbTargetedNonWQStage3. I am calculated with sum of these textbox and compare with balance which I have taken variable. In balance my values is coming with textbox name tbTargetedNonWaterQuality, tbCurrentMonthNonWaterQuality doing with minues(-). And compare with these fout textbox. Now I want if user change any of values of textbox (four textbox) then my sum must be match with balance if balance is greater than display alert message as like ‘alert(' Targeted Balance Habitation should be equal to Targeted habitation'); and cursor must be focus on that textbox which is values changes. I want these coding in javascript..

I am providing following coding in javascript..

function ValidTargetNonWater() {
var TargetedNonWater = document.getElementById('<%= tbTargetedNonWaterQuality.ClientID %>').value;
TargetedNonWater = parseFloat(TargetedNonWater);
if (isNaN(TargetedNonWater))
TargetedNonWater = 0;

var CurrentMonthNonWater = document.getElementById('<%= tbCurrentMonthNonWaterQuality.ClientID %>').value;
CurrentMonthNonWater = parseFloat(CurrentMonthNonWater);
if (isNaN(CurrentMonthNonWater))
CurrentMonthNonWater = 0;

if (TargetedNonWater > CurrentMonthNonWater) {
var balance = (TargetedNonWater - CurrentMonthNonWater);

var stage1 = document.getElementById('<%= tbTargetedNotWQStarted.ClientID %>').value;
stage1 = parseFloat(stage1);
if (isNaN(stage1))
stage1 = 0;

var stage2 = document.getElementById('<%= tbTargetedNonWQStage1.ClientID %>').value;
stage2 = parseFloat(stage2);
if (isNaN(stage2))
stage2 = 0;

var stage3 = document.getElementById('<%= tbTargetedNonWQStage2.ClientID %>').value;
stage3 = parseFloat(stage3);
if (isNaN(stage3))
stage3 = 0;

var stage4 = document.getElementById('<%= tbTargetedNonWQStage3.ClientID %>').value;
stage4 = parseFloat(stage4);
if (isNaN(stage4))
stage4 = 0;

var totalStage = (stage1 + stage2 + stage3 + stage4);

if (totalStage != balance) {
alert(' Targeted Balance Habitation should be equal to Targeted habitation');
document.getElementById('<%=tbTargetedNotWQStarted.ClientID %>').focus();


(No response found.)

Login to post response