How can I convert the values of an input field from a string to an integer
with javascript? How can I use the parsInt() function?
I am making a timer with javascript and I have a form where a user inputs
the minutes and seconds then when they click submit a getTime() function
is ran so a time variable is created. It is recognizing the time variable
as a string not a number and I am getting NaN. How can I get the values of
the id's "mNumbers" and "sNumbers" through the parsInt() to convert them
to numbers and get rid of the NaN error? Or is there a better way?
Here is the html form code:
<form id="timer" onSubmit="return getTime();">
<input type="number" name="Mintues" id="mNumber">Minutes <br >
<input type="number" name="Seconds" id="sNumber">Seconds <br >
<input type="submit" name="Submit" value="Submit" class="btn">
</form>
here is the javascript I have:
function getTime() {
var minutes= parsInt($('#mNumber').val() * 10000);
var seconds=parsInt($('#sNumber').val() *1000);
var time = minutes + seconds;
return time;
}
No comments:
Post a Comment