0

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

4
Contributors
5
Replies
14
Views
2 Years
Discussion Span
Last Post by Danny159
0

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

0

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

0

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));
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.