By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,581 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

Time in combobox

P: n/a
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

Jul 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ja*********@gmail.com wrote:
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,

--
Bart

Jul 1 '06 #2

P: n/a
JRS: In article <11*********************@j8g2000cwa.googlegroups.c om>,
dated Sat, 1 Jul 2006 05:29:59 remote, seen in
news:comp.lang.javascript, Bart Van der Donck <ba**@nijlen.composted :
>
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 ***

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.