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 6681367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:34:55+00:00 2026-05-26T04:34:55+00:00

I have a prompt that basically is a required field and cannot contain a

  • 0

I have a prompt that basically is a required field and cannot contain a decimal. I have a while loop that should continue to prompt the user for information until a number is indicated regardless of whether OK or Cancel are clicked. Everything works fine as long as the OK button is clicked. It continues to prompt if left blank and OK is clicked or if a number with a decimal is provided and OK is clicked. But if cancel is clicked, it doesn’t continue to prompt.

var rmiles = prompt("Please indicate actual miles driven for payroll");
    while (rmiles == null | rmiles == "null" | rmiles == " " | rmiles.indexOf(".") != -1) {
        alert("Mileage is required when arriving on site and can only be whole numbers.  No Decimals.  Please enter 0 if you did not intend to arrive on site.");
        rmiles = prompt("Please indicate actual miles driven for payroll");
    }
  • 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-26T04:34:56+00:00Added an answer on May 26, 2026 at 4:34 am

    I believe the problem is in your while condition – you are doing bitwise OR | on all the conditions. This means that rmiles.indexOf(".") is always called, even when rmiles is set to null by prompt when Cancel is clicked. This is because bitwise OR will not short-circuit.

    Try the logical OR || which does short-circuit and thus avoids the null reference error:

    while (rmiles == null || /*...*/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that prompt the users to enter serial number for a
For some reason the Windows command prompt is special in that you have to
I have implemented a LoginAccess class that prompts the user to enter their active
I have a standalone application in which I have to prompt the user with
I'm interested in using a JavaScript Prompt to have the user enter data. Any
I have a situation that users access remote MySQL server in C# application. Basically,
I have a Django website that basically just displays a bunch of items from
I’m trying to make an über-simple (single-character) prompt that gives me as much information
Well, the subject says it all, basically. I have a command-line utility that may
I have a couple of functions. Basically a menu where a user can choose

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.