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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:24:08+00:00 2026-05-24T19:24:08+00:00

EDIT: Ok so I’m updating this question, to show what I’ve built as I’ve

  • 0

EDIT:

Ok so I’m updating this question, to show what I’ve built as I’ve still not been able to fix this issue. Here is an image of what I’ve got. So as you can see,

enter image description here

When the user enters a value, the calculation (they are just percentage and total calculations are done “onkeyup”. As you can see because of this they return “NaN”. Is there a way for me to stop the field displaying a NaN and then subsequently only showing the total values?

I have thought about this and I could just get all the fields to calculate as soon as something is input into the final field? What do you think. Apologies to all those that had perviously answered my question, I am still trying to figure out the best approach, I’m just not as good with JavaScript as I am with HTML/CSS!!

  • 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-24T19:24:09+00:00Added an answer on May 24, 2026 at 7:24 pm

    You should try writing a checkNumber function that takes the entered value as its argument (rather than referring directly to each field inside the function). Something like this:

    var checkNumber = function (testval) {
      if ( isNaN(testval) ) {
        alert('Bad!');
        // clean up field? highlight in red? etc.
      } else {
        // call your calculation function
      }
    }
    

    Then bind that function to the keyup event of each form field. There are a number of ways to do this. Look into addEventListener(), or the binding features of a framework like jQuery (.delegate() or .keyup(), e.g.).

    Note that if you do bind the function to the event, you won’t have to explicitly pass in the value argument. You should be able to work with a field’s value within the function via this.value. So you’d have something like this:

    var checkNumber = function () {
      if ( isNaN( this.value ) ) {
        alert('Bad!');
        // clean up field? highlight in red? etc.
      } else {
        // call your calculation function
      }
    }
    

    And then (with a naive binding approach by ID):

    document.getElementById('id_of_a_field').addEventListener('keyup', checkNumber, true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT - I was able to fix this problem using code from 'Farray' with
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
Edit (updated question) I have a simple C program: // it is not important
Edit: The below question was answered by this . I have a new updated
Edit: I'm looking for solution for this question now also with other programming languages.
EDIT: I rephrased the question because I have not explained well. Let's see if
EDIT: This question was exceptionally dumb and made me look like a script kiddie,
EDIT: looking for this: http://diminishing.org/extending-formtastic-with-a-sprinkle-of-jquery (If this works I'll answer my own question) I've
Edit 4: I was finally able to solve my own issue. See checkmark answer
Edit: This question was written in 2008, which was like 3 internet ages ago.

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.