aslum
aslum

Reputation: 12254

Update Time when user clicks buttons

Apparently I don't understand .val() very well. I'm trying to have buttons where the user can click them and input the number of hours read. However I can't even get the basic buttons to work. Hopefully if I can get it working it won't be too hard to make the 4th click of the quarter hour button roll-over appropriately. Here's my code, maybe you can tell me what dumb thing I'm doing:

HTML:

Time (H:MM): <span id="hoursread">0</span>:<span id="minutesread">00</span><br>
<button id="fifteen">+15 Minutes</button>
<button id="sixty">+1 Hour</button>
<button id="minus">-1 Hour</button>

jQuery:

$('#sixty').click(function () {
    $('#hoursread').val(+1);
});
$('#fifteen').click(function () {
    $('#minutesread').val(+15);
});
$('#minus').click(function () {
    $('#hoursread').val(-1);
});

I've been fiddling with this to no avail!

Upvotes: 0

Views: 39

Answers (1)

Adil
Adil

Reputation: 148110

You need to use text() insead of val() for span having id hoursread, val() is used for input elements. Although you will have to calculate the time interval.

Upvotes: 2

Related Questions