Hello,
First post here?
I am trying to do two validations at a time:
1.
I am trying to convert “,” to “.” before calculation. Then “.” to “,” after calculation. The reason behind this is we have “,” as decimal seperator (3,113 for example). It is likely possible that user will enter “,” as decimal seperator. This is solved.
I am trying to restrict user input to numbers (1…0, 1..0 in Numeric pad, cursor keys, back key, comma and decimal key). Now here I don’t know what should I do and how to do that :/
The code for decimal seperator conversion is here.
[quote]
function calculateBMI() {
document.datacollectionentry.weight.value = document.datacollectionentry.weight.value.replace(“,”,”.”);
var weight = eval(document.datacollectionentry.weight.value);
var height = eval(document.datacollectionentry.height.value);
var height2 = height / 100;
var BMI = weight / (height2 * height2);
document.datacollectionentry.bmi.value=custRound(BMI,1);
document.datacollectionentry.bmi.value = document.datacollectionentry.bmi.value.replace(“.”,”,”);
document.datacollectionentry.weight.value = document.datacollectionentry.weight.value.replace(“.”,”,”);
}
function custRound(x,places) {
return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places);
}
And the function is returned like this:
[quote]
<input type=”text” name=”weight” size=”5″ maxlength=”5″ value=”” onblur=”calculateBMI()” />
I do know that I need to restrict user input before bmi function. I don’t know how to do that. Can somebody please help me here?