Hi I have javascript function which doesnot allow the user to enter the amount in a text box if the
amount entered in fundsamount text box is greater than remaining funds. Remaining funds is a text box and is pre populated from database with $ sign in front
like($5000.00).
Alert should be displayed in both cases whether the user enters a $ sign or not in front of the numbers
My problem is that my alert does not display the correct number if the remainingfunds is $888.00
the alert shows 88.0 so if the user enters 800.00 it gives the alert which is wrong since it compares 800 with 80 instead of 800 with 880
The alert should also be displayed if the remainingfunds is a -ve number diaplyed as ($9,314.24) on screen.
function IsNumber(e)
{
var num = e.value.replace(/[$]/,"");
var num = e.value.replace(/[,]/,"");
num = num.toString().replace(/[^
0-9.]/g,''
);
return num;
}
function SubFundAmount()
{
var Remainingfunds= IsNumber(window.document.g
etElementB
yId('<%=re
mainingfun
ds.ClientI
D %>'));
var fundsAmount = IsNumber(window.document.g
etElementB
yId('<%=fu
ndsamount.
ClientID %>'));
var Remainingfunds= = parseFloat(RemainingBudget
.substr(1)
)
alert(Remainingfunds)
if fundsAmount > Remainingfunds)
{
alert("WARNING: amount cannot be greater than remaining fund.");
window.document.getElement
ById('<%=f
undsamount
.ClientID %>').focus();
window.document.getElement
ById('<%=f
undsamount
.ClientID %>').select();
return false;
}
else
{
window.document.getElement
ById('<%=n
otes.Clien
tID %>').focus();
window.document.getElement
ById('<%=n
otes.Clien
tID %>').select();
return true;
}
}
I also have the ffollowing function in my common js file that is included in the page
function ValidNumber( formElem )
{
if (formElem.value == "") formElem.value = "0";
return formElem.value;
}
Start Free Trial