Forum Moderators: open
function add() {
var number1=box1.value;
var number2=box2.value;
var number3=Math.abs(number1+number2);
box3.value=number3; }
If box1.value is "2" and box2.value is "3" it box3.value should come out as "5" but instead it comes out as "23".
for floats/decimals
parseFloat(number1) + parseFloat(number2)
If you're wondering what the second parameter (10) in parseInt is for:
radix [ - the second parameter]
Optional. A value between 2 and 36 indicating the base of the number contained in [the first parameter]. If not supplied, strings with a prefix of '0x' are considered hexadecimal and strings with a prefix of '0' are considered octal. All other strings are considered decimal.- from MicroSoft's JScript documentation
So if you put the string "09" into parseInt without specifying base10 as the radix you'll end up with an octal integer.... I had some crazy fun with this once when I didn't have a monkeys what was going on!