Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 846167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:34:16+00:00 2026-05-15T06:34:16+00:00

I have the following code if (msg.position == 0) //removed for brevity else if

  • 0

I have the following code

if (msg.position == 0)
    //removed for brevity
else if (msg.position == txtArea.value.length)
    //removed for brevity
else {
    //ERROR: should not reach here.
    errorDivTag.innerHTML += msg.position + " " + txtArea.value.length;
}

I’m having some really weird situations where I’m getting the error in the last code block, but the printed positions show that msg.position is in fact equal to the txtArea.value.length. This only happens 1% of the time, almost as if I have some kind of race-condition in my code where the two are NOT equal during the second if statement, but equal when I print in the error message.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:34:17+00:00Added an answer on May 15, 2026 at 6:34 am

    To start with, always use ===. That will prevent JavaScript from automatically coercing the types in the comparison, which means you’ll be able to spot all sorts of bugs much more easily. In this case, it’s possible you have some whitespace (which is basically impossible to see in the output) that is causing a string comparison instead of the (I assume) desired numeric comparison.

    Also, I’m assuming you really meant to have { after your if and else if conditions. If not, that could be causing all sorts of strange behavior, depending on the code you removed due to brevity concerns. If you didn’t, then you’ve got an extraneous } before your else condition.

    UPDATE: Set a breakpoint in Firebug/DeveloperTools/DragonFly/whatever and inspect the values as the comparison occurs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code : <input type=text value=<?php echo $_GET['msg']; ?>> This input
I have following html code <input type=button id =b1 value=Click me onclick=msg() /> <input
I have following PHP code: if($_SESSION['msg']['login-err']) { echo '<p class=error>'.$_SESSION['msg']['login-err'].'</p>'; unset($_SESSION['msg']['login-err']); } Everything working
I have following code using hibernate to throw a custom exception on error and
I have the following code (minus some other operations): def foobar(): msg=None if foo:
I have the following code: MSG mssg; // run till completed while (true) {
I have the following code : msgtxt = é msg = MIMEText(msgtxt) msg.set_charset('ISO-8859-1') msg['Subject']
I have the following code: <form action= method=get onsubmit=doRequest($('word').value); $('word').value=''; return false;> <input type=text
I have the following code it only works in IE6: if(document.getElementById(IsOnline).value == 'True') {
I have the following code which works fine in notepad but not in WORD!!

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.