Solved

NaN error

Posted on 2000-05-12
7
1,754 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JavaScript Loan Calculator Error 3 34
Triple line in an alert message 4 22
null, truthy, falsey confusion 25 30
15 puzzle in Javascript/html 2 39
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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

749 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