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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...