I have an amount field but when the user tabs out the field, if they havn't added a decimal i want to add '.00' when they tab out the field.
Thing is i have no idea on how to do a check if it contains a '.'. I know how to add the '.00'
This is my code so far
function AddDecimalToAmounts()
{
var ApproxAmount = $("#ApproximateValue_TextBox").val();
var ApproxAmountVis = $('#chqAdditional_div').is(':visible');
var UncryAmount = $("#UncryAmount_TextBox").val();
var UncryAmountVis = $('#chqAdditional_div').is(':visible');
if (ApproxAmountVis == true && UncryAmountVis== true)
{
if (//Code for if both amount fields are displayed and to add '.00' or not)
{
}
}
else if (ApproxAmountVis == false && UncryAmountVis== true)
{
if (//Code for if only the UncryAmount amount field is displayed and to add '.00' or not)
{
}
}
else if (ApproxAmountVis == true && UncryAmountVis== false)
{
if (//Code for if only the ApproxAmountVis amount field is displayed and to add '.00' or not)
{
}
}
}
.the same way you check for any other string. What's the problem? Don't you know aboutindexOf()?if (value.indexOf('.') == -1) { /* add the decimals */ }1.1, wouldn't you like to change it to1.10? Just usetoFixed(2)to give it 2 digits after the decimal no matter what the original was.