Increment time in form

T

Targa

I have a form field which displays a time in the format 5:30 PM - this time
is selected from a previous page.
I need to add a function to increment or deincrement the time by clicking
up/down buttons - sort of like the clock in Windows.

How can this be done in javascript?

Thanks in advance!
 
V

Vincent van Beveren

// disassambles to values
function processToValues() {
value = document.myform.time.value;
column = value.indexOf(":");
space = value.indexOf(" ");
half = value.substring(space+1);

// half would now countain PM or AM
hours = value.substring(0, column);
minutes = value.substring(column+1,space);
}

function increment() {
minutes++;
if (minutes>59) {
minutes=0;
hours++;
if (hours==12) {
// am->pm->am
// for now, case sensetive
half = (half=='PM'?'AM':'PM');
}
if (hours>12) {
hours = 1;
}
}
}

You should be able to figure out the rest. Good luck,
Vincent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top