Yep - parseInt() or parseFloat().
When you are pulling data from HTML you will get something like "55"
rather than 55 (notice the quotes). So then doing something like this:
var count = $("#mydiv").text() + 100;
WOuld result in count being set to "55100" (assuming the div had 55 in it).
Also, your code is wrong. Where you are getting your startmin/stopmin
variables - you are saying "put the jQuery object representing this
elements into this variable". Whereas you seem to be meaning "put the
values contained within these elements into these variables". So you
would need to change that to read something like this:
var startmin = parseInt( $("timestartmin").text() );
var stopmin = parseInt( $("timestopmin").text() );
//check to make sure you didn't get a NaN
if (!startmin) startmin = 0;
if (!stopmin) stopmin = 0;
The second part where the sanity check is being applied may not be
applicable in your case.
HTH
Shawn
Vlad Mazek wrote:
Is there something special that needs to be done to values selected with
jQuery so math functions can work on them? parseInt or something? I am
not sure, but all my calculations are getting NaN. For example, I have
the following function that always produces NaN:
var startmin = $("#timestartmin");
var stopmin = $("#timestopmin");
var totaltime = startmin - stopmin;
$("#totaltime").val(totaltime); }
I've tried adding .val to the first two lines, I've tried parseInt to
separate temp variables, I just keep on getting NaN even though it is
pulling numbers from the two fields. Any ideas?
-Vlad