I’m doing some calculations in javascript. Everything looks fine until I want to submit the form. It doesn’t work, why not?
Then the user puts a value in one field, calculation is made in an another field. This works fine in the browser, until I make the next step and try to save the form with submit().
Here is my code, in the onBlur event of a field.
frm.Taxfree_1.value=Math.round(frm.Km_1.value1.110)/10
I think that the problem is the multiplication of 1.1. Can I solve this another way?
Thankful for help.
/Carola
Subject: Javascript calculation
First of all if you think that the problem is 1.1 then why not multiply by 11 instead of 1.1*10.
Secondly if the calculation is working in the UI (which javascript does) then it probably isn’t the cause of your submit problem.
Is your field a number field? I had an awful problem with number and date fields in the past and worked around it by ensuring that all such fields were text fields with a keyCheck function to ensure that no unwanted characters are used.
i.e. on the text field input type=“text” onKeyPress=“return keyCheck(event, this)”
In the JavaScript header
//Start of keyCheck function
function keyCheck(eventObj, obj)
{
var keyCode
// Check For Browser Type
if (document.all)
{
keyCode=eventObj.keyCode
}
else
{
keyCode=eventObj.which
}
var str=obj.value
if(keyCode==46)
{
if (str.indexOf(".")>0)
{
return false
}
}
if(keyCode==47)
{
if (str.indexOf("/", 3)>3)
{
return false
}
}
if((keyCode<46 || keyCode >58) && (keyCode != 46) && (keyCode != 127) && (keyCode != 0)){ // Allow only integers, decimal points and delete key
return false
}
return true
}
//EOF
Subject: RE: Javascript calculation
Thanks for your help.
I tried to multiply by 11 and it didn’t work. It only worked if I removed 1.1 and multiplied by 10.
So,I changed my fields to text fields and used your keyCheck. It works fine now.
/Carola