Hi,

I have a field that a user add's a curreny value to, on keyup I fire a Javascript function that checks the following but its not working at all...

What I want it to do is... user add's say 10
On keyup the Javascript needs to add .00 to the end... to make it 10.00

But if the user puts 10.00 or 10.25 it doesnt do anything and leaves it as it.

Help!
Thanks
Dan

Provide a sample of the code you are having trouble with so we can take a look and help you.

Member Avatar
varName.toFixed(2)

may do it.

Thanks for your replies, still havent got this working code below:

function ValidateNumber(){
    console.log($("#amount").val());
    var vamount = $("#amount").val();
    //$("#amount").val(vamount.replace (/(\.\d\d)\d+|([\d.]*)[^\d.]/, '$1$2'));
    $("#amount").val().toFixed(2);
    console.log($("#amount").val());
}

Thanks

Sorted, I needed to change the string to a float.. see working function below:

function ValidateNumber(){
    var vamount = parseFloat($("#amount").val());
    $("#amount").val(vamount.toFixed(2));
}