Solved

NaN error

Posted on 2000-05-12
7
1,760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

623 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