Time in combobox

J

jayender.vs

Hi,
I need to display the time in combo box like the one we have it in
Wndows 2000.
we can change the time using the arrow.. it looks like this:

4:40:54 PM

in a combo box .
i need to do it like his in my page.
waiting for ur response.
Ciao,
jay
 
B

Bart Van der Donck

I need to display the time in combo box like the one we have it in
Wndows 2000.
we can change the time using the arrow.. it looks like this:

4:40:54 PM

in a combo box .
i need to do it like his in my page.

<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">

var usrHours = 0;
var usrMinutes = 0;
var usrSeconds = 0;

function showTime(h,m,s) {

var now = new Date();

if (
now.getHours() + usrHours + h > 23 ||
now.getHours() + usrHours + h < 0 ||
now.getMinutes() + usrMinutes + m > 59 ||
now.getMinutes() + usrMinutes + m < 0 ||
now.getSeconds() + usrSeconds + s > 59 ||
now.getSeconds() + usrSeconds + s < 0
) {
return false;
}

usrHours+=h;
usrMinutes+=m;
usrSeconds+=s;
var hours = now.getHours() + usrHours;
var minutes = now.getMinutes() + usrMinutes;
var seconds = now.getSeconds() + usrSeconds;
var timeNow = hours;
if (hours >= 12) {
timeNow -= 12;
var ext = 'PM';
}
else {
var ext = 'AM';
}

timeNow += ((minutes < 10) ? ':0' : ':') + minutes;
timeNow += ((seconds < 10) ? ':0' : ':') + seconds;
timeNow += ' ' + ext ;
document.f.myCombo.value = timeNow;
setTimeout('showTime(0,0,0)', 1000);

}

</script>
</head>

<body onLoad="showTime(0,0,0);">
<form name="f">
<input size="13" name="myCombo">
</form>
<br>
<input type="button" value="hrs++" onClick="showTime(1,0,0);">
<input type="button" value="hrs--" onClick="showTime(-1,0,0);">
<input type="button" value="min++" onClick="showTime(0,1,0);">
<input type="button" value="min--" onClick="showTime(0,-1,0);">
<input type="button" value="sec++" onClick="showTime(0,0,1);">
<input type="button" value="sec--" onClick="showTime(0,0,-1);">
<input type="button" value="Reset"
onClick="usrHours=usrMinutes=usrSeconds=0; showTime(0,0,0);">
<hr>
Max value of seconds and minutes is 59.<br>
Min value of seconds and minutes is 0.<br>
Max value of hours is 11 PM.<br>
Min value of hours is 0 AM.
</body>

</html>

Hope this helps,
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Sat, 1 Jul 2006 05:29:59 remote, seen in
news:comp.lang.javascript said:
Hope this helps,

Better to encourage the use of the sensible 24-hour notation, which is
easier. Your code shows 0 AM & 0 PM, which is not customary in English-
speaking countries.

ISTM that one should probably stop the clock on the first click.

I think it would be better to use a Date Object, and, at each button-
click, add 1000 * +-1 * (1 or 60 or 3600) using setTime, and display it.
Then one gets automatic rollover, and cannot (in the Netherlands) on
2006-03-26 set a time between, if I have it right, 02:00:00 to 02:59:59.

I won't code it, because I consider it much easier just to type the
desired time as hh:mm:ss.


** OP : DO NOT MULTI-POST ***
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top