Solved

NaN error

Posted on 2000-05-12
7
1,752 Views
Last Modified: 2006-11-17
Can anyone tell me what is wrong with this script?  It's just a basic javascript to calculate a field based on what the user has returned.  It's fired on the "OnChange" event... however, it's returning a NaN value.  Help!

function calcmember() {

      var membertotal;
      membertotal = theForm.mem_num.value * 210;
      theForm.memTotal.value = membertotal;
      }
0
Comment
Question by:stewmic1
  • 3
  • 3
7 Comments
 
LVL 2

Expert Comment

by:lilian_kelly
ID: 2805498
Its returnnig the value of mem_num as a string, hence NaN (not a number).

To get over this use
membertotal = eval(theForm.mem_num.value) * 210;

That should fix it
0
 
LVL 1

Author Comment

by:stewmic1
ID: 2805515
Sorry, but this didn't work.  It's still returning NaN.
0
 
LVL 2

Expert Comment

by:lilian_kelly
ID: 2805549
What are the typical values that  theForm.mem_num.value would contain?

Check that by alerting the value that it contains. If this is blank then you will get NaN
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:stewmic1
ID: 2805556
The field is just grabbing how many people will be attending an event, so i'm using simple numbers, such as 2... not leaving it blank.  i plan on validating the form... as soon as i get this problem resolved.
0
 
LVL 2

Accepted Solution

by:
lilian_kelly earned 50 total points
ID: 2805579
I am a bit stumped. Here is the sample that I am using to check this out and I cannot get it to produce Nan

<HTML>
<HEAD>
<script>
function calcmember() {

var membertotal;
membertotal = eval(document.theForm.mem_num.value * 210);
document.theForm.memTotal.value = membertotal;
}
</script>


</HEAD>
<BODY>
      <form name="theForm">
      <input type="text" name="mem_num">
      <input type="text" name="memTotal">
      <input type="button" value="calc" onclick="calcmember()">
      </form>
      
</BODY>
0
 
LVL 3

Expert Comment

by:bark10
ID: 2805606
Try this instead of eval()

 =(parseInt(theForm.mem_num.value,10)*210)
0
 
LVL 1

Author Comment

by:stewmic1
ID: 2805616
He he... boy do i feel dumb!  It was working all along... i just had another text box on my page that was named the same thing.   oops!  thanks for your help anyway!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Generate Numbers in JQuery file 11 66
Add shadow behind div 5 25
suddenly angular cli doesn't work. 5 39
jQuery on Submit 4 42
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question