Log in

View Full Version : JS Help



MrCraig
17-01-2008, 05:46 PM
Ok,

I have this code, which is meant to add something on to the value currently displayed.

Heres the code so far:


function calc(hcs)
{
try{
var cur = document.getElementById("calcscreen").innerHTML;
cur = cur+hcs;
document.getElementById("calcscreen").innerHTML = cur;
}
catch(err)
{
alert(err);
}
}
function cls()
{
document.getElementById("calcscreen").innerHTML = 0;
}


Whats going wrong is that if we use the calc(2.0); function, if the initial display was 0 it would become

02

Then if we do again it would become

022

I think its making the variables string and as such, not adding correctly, if this is the case, does anyone have the code to turn them back into integer/single?

Thanks for any help =]

MrCraig
18-01-2008, 11:01 PM
Sorry to double post,

But does anyone know a way to get round this error?

Want to hide these adverts? Register an account for free!