Solved

jQuery/Javscript math calculation not working

Posted on 2011-09-04
2
336 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
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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
Comment Utility
Of course, I missed the val(). Thank you.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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)

728 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

14 Experts available now in Live!

Get 1:1 Help Now