Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare current time with the selected item in the dropdown

Status
Not open for further replies.

nubees

Programmer
Aug 6, 2003
39
US
Hello all,

When a person selects a value from the dropdown list and hits submit. the form should be validated before sending to next page.
The selected hour should not be greater than or less than the current hour. In other words if the current time is 4:32 then he should select 4:00 not 3:00 or 5:00.
Code:
<select name="hr" id="select2">
              <option value="01:00">01:00</option>
              <option value="02:00">02:00</option>
              <option value="03:00">03:00</option>
              <option value="04:00">04:00</option>
 		....
		.....             
              <option value="22:00">22:00</option>
              <option value="23:00">23:00</option>
              <option value="00:00">00:00</option>
            </select>

<input type="submit" name="Submit" value="Click Here To Submit" ONCLICK="CheckTime()">
please help

this is what I wrote so far..
Code:
<SCRIPT LANGUAGE="JavaScript">
	function CheckTime() {
	var selected_value = this.form.hr.value;
	var currentTime = new Date()
	var hours = currentTime.getHours()
	var strTime = hours +":00" +" "
	
	if(strTime>selected_value) {
		alert("Please select correct time");
		return false;
	}
	return true;
	}
</SCRIPT>
The code I have written is not working some how.. Please help many thanks in advance

nubee
 

If you are going to use JS anyway, why not just deliver only the value to the page that matches the current hour?

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
I am using Dreamweaver to build the webpage..

Can you tell me how I can do that?

I want to send that time to the database when submit is clicked. I just want the hour no minutes. like 4:00, 5:00 etc. and also it should go beyond 12:00 like 13:00, 14:00 and there should be no 24:00 after 23:00 but 0:00

Is it possible?

I think I can use a textbox with the current hour showing in it. but how can i accomlish it??

thanks for your suggestion
 
Something like this should work:

Code:
<html>
<head></head>

<body onload="document.forms[0].elements[0].value = new Date().getHours();">
	<form>
		<input />
	</form>
</body>
</html>

Hope this helps,
Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top