I am new.
When I try to add a variable and a number from a textbox they add as strings:
var m=(window.document.myform.mo.value);
var b=m+24
if m=12 then I get b=1224
Now when I add number to it I get an error in the page:
var m=number(window.document.myform.mo.value);
var b=m+24
I am sure all the other code is correct.
How do you change a variable into a number format?
felgall
2
The simplest way is:
var m=+(window.document.myform.mo.value);
var b=m+24
What happens if I want to use a decimal # that should not be truncated?
rpkamp
4
parseInt will truncate it, use parseFloat instead
system
5
another option is to use the javascript Number Class
rpkamp
6
Use parseInt
var m=parseInt(window.document.myform.mo.value, 10);
var b=m+24