Change a variable into a number format

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?

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?

parseInt will truncate it, use parseFloat instead :slight_smile:

another option is to use the javascript Number Class

Use parseInt

var m=parseInt(window.document.myform.mo.value, 10);
var b=m+24

:slight_smile: