Solved

NaN error

Posted on 2000-05-12
7
1,742 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now