Jump to content

Arithmetic Coding Problem


Recommended Posts

I don't know why I am getting "011" instead of "2" after 2 times through my function.

My code is:

<input name=\"ent2a\" type='number' id=\"ent2a\" size=\"1\" style=\"text-align:center\" MaxLength=2 value=0 onblur=\"chkent(ent2a)\">

<input id='cntR' type='number' size='1'  MaxLength=2 value=0>

function chkent(entry)
{with (entry);
var e = entry.value;
if(e==1){cntR.value = cntR.value + 1;return false;}
return false;}

Link to comment
Share on other sites

Because the "+" operator concatenates strings as well as adding numbers. The computer determines which operation to do based on the data type of the variables. The value property of an HTML form control is always a string, so you have to convert it to a number before doing number operations on it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...