Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

NaN error

Posted on 2000-05-12
7
Medium Priority
?
1,771 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
Technology Partners: 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 200 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

Technology Partners: 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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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

972 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