Solved

jQuery/Javscript math calculation not working

Posted on 2011-09-04
2
347 Views
Last Modified: 2012-05-12
On this screen:

https://www.interactivehealthpartner.com/mfc_goals.asp

Click Weight Management, enter some pounds to lose and click "calculate now". For the first box on the right, Daily calorie reduction need to accomplish your goal, this is the equation:

Daily_calorie_reduction = total_number_of_days_in_goal_period / (pounds_to_lose*3500)

The part of my code which accomplishes this is attached, but I keep getting NaN. Is there something obvious I am doing which won't allow this to calculate? Thank you!
var weight2aStartDate=Date.parseExact($('#startdate option:selected').val(), 'M/d/yyyy');
var weight2aBegin=Date.parseExact($('#startdate option:selected').val(), 'M/d/yyyy');
var weight2aTerm=parseInt($('#term').val());
var weight2aEnd=weight2aStartDate.addMonths(weight2aTerm);
var weight2a=parseInt(days_between(weight2aBegin, weight2aEnd))/(parseInt($('#weight1b'))*3500);
alert(weight2a);

Open in new window

0
Comment
Question by:bbdesign
[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
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36480518
replace line 5 :
var weight2a=parseInt(days_between(weight2aBegin, weight2aEnd))/(parseInt($('#weight1b'))*3500);
by :
var weight2a=parseInt(days_between(weight2aBegin, weight2aEnd))/(parseInt($('#weight1b').val())*3500);
0
 

Author Comment

by:bbdesign
ID: 36481040
Of course, I missed the val(). Thank you.
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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
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…

687 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