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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:19:12+00:00 2026-06-13T07:19:12+00:00

I have an order form and a JavaScript which should calculate grand total from

  • 0

I have an order form and a JavaScript which should calculate grand total from textbox (quantity*price), checkbox and radio, but I’m missing something because i receive a NaN error. Could somebody help me fix it?
Thanks a lot.

DEMO

  • 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-06-13T07:19:13+00:00Added an answer on June 13, 2026 at 7:19 am

    Like many have commented, there are some serious short-comings to your code. I won’t re-iterate these concerns, however, they are very important and you should learn as you are getting more acquainted with the technologies you are using.

    The reason you are getting a NaN is this. Your fields object is an array. Your code populates the fields array at an arbitrary indices, i.e. fields[f] = 0;

    When you populate the array for index, say 5, your code does this fields[5] = 0;. With this statement you went from having an empty array [], to having an array with 6 entries with the first 5 entries being defaulted to undefined [undefined, undefined, undefined, undefined, undefined, 0].

    Now later in your code when you do the summation and add the arrays entries up (using eval having prepared a string) these …undefined+0+undefined+8… are producing a Not A Number error.

    Instead, one way to prevent this is to push entries onto the fields array like:

    if (userInputs[f].value)
    {
      fields.push(userInputs[f].value);
    }
    else
    {
      fields.push(0);
    }
    

    push will add one entry to the end of the array. [] will become [0] if you push(0).

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

Sidebar

Related Questions

We have an order form which takes credit cards from mobile browsers: <input type=number
I am trying to use a textarea form entry which I have some javascript
I have radio buttons which when selected populate a dropdwn menu from mysql. Below
I have an issue i am trying to modify a form's tab order which
I have an html form which uses jquery focus and blur in order to
I have an order form with about 30 text fields that contain numerical values.
I have a multi-step order form built in this manner: Step 1: Choose category
I have inherited a project, that provides an order form to a customer. The
I have a registration form and used fieldset to order the input fields in
I have an Order model, which has_many payments and a checkout Controller. The Controller

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.