Hi Frendz,
I have two text fields 'from time' and 'to time'. The time format of the two text fields are 11:30 am 01:30 pm. I want to give alert message in javascript when the users enter the to time less than the from time.

Recommended Answers

All 2 Replies

<script language="javascript"> 
	function validate(dt1,dt2)
		var jdt1=Date.parse('20 Aug 2000 '+dt1);
		var jdt2=Date.parse('20 Aug 2000 '+dt2);
			alert('invalid start time');
			return false;
			alert('invalid end time');
			return false;
	  	if (jdt1>jdt2)
			alert('start is greater');
			alert('start is less equal');
<form name=frm id=frm action=temp.php method="get" accept="text/csv">
start <INPUT id=txt1 name=txt1 value='10:30:05 am'>&nbsp; <br>
end <INPUT id=txt2 name=txt2  value='10:40:05 am'>&nbsp; 
<input type=button value=ok id=button2 name=button2 onclick ='validate(document.frm.txt1.value,document.frm.txt2.value)'>&nbsp;&nbsp; 
<script language='javascript'> 
<div id="txtHint">&nbsp;
commented: Helpful post +6

Thanks Urtrivedi. My problem is solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.