Reputation:
For a timer(minutes:seconds)if it has time of 30:00 how to increase the minutes part of it and display it in a input box?
My Html Code is
<input name="timer" id="timer" value="30:00" type="text" onclick="incre()"></input>
My javascript code is
function incre()
{
var textbox = document.getElementById("timer");
var time = document.getElementById("timer").value.split(":");
var minutes = parseInt(time[0]);
var seconds = parseInt(time[1]);
minutes = minutes++;
}
Upvotes: 0
Views: 401
Reputation: 3144
Try this:
function incre() {
var textbox = document.getElementById("timer");
var time = textbox.value.split(":");
var minutes = parseInt(time[0]);
var seconds = parseInt(time[1]);
minutes++;
textbox.value = minutes + ':' + seconds;
}
Note that minutes = minutes++
is unnecessary, you just need to do minutes++
.
With the last line, you update the input's value.
Upvotes: 1
Reputation: 167172
You are increasing minutes, alright. But you are not updating it in the text field. Also, read the basics. There's no </input>
.
parseInt()
for 0
.minutes++
to minutes
.function incre() {
var textbox = document.getElementById("timer");
var time = document.getElementById("timer").value.split(":");
var minutes = parseInt(time[0]);
var seconds = (time[1]);
minutes++;
document.getElementById("timer").value = minutes + ":" + seconds;
}
<input name="timer" id="timer" value="30:00" type="text" onclick="incre()" />
Upvotes: 1