0

Hey ppl,

I have a form with the start date and end date fields...

I want to check if bothe fields are filled and also to check if the start date is earlier than the end date...

<form id="form1" name="form1" method="post" action="get2.php" onSubmit="return validateform(this)">

Checking code...
<script language="javascript">
<!--
function validateform(form1)
{

	 if(form1.date5.value=='0000-00-00')
	{
		alert('Select the Start Date');
		return false;
	}
	if(form1.date6.value=='0000-00-00')
	{
		alert('Select the End Date');
		return false;
	}
	return true;
}

This code checks if the fields are filled... but i don't knw how to make sure if the start date is earlier than end date...

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by rajabhaskar525
0

do like this.

<?php
$start = new DateTime('08-06-1995 Europe/Copenhagen'); // DD-MM-YYYY
$end = new DateTime('22-11-1968 Europe/Amsterdam');

if ($start < $end) {
    echo "Correct order";
} else {
    echo "Incorrect order, end date is before the starting date";
}
?>

for refrence see this link hope it will helps you.

0

in javascript

var myDate=new Date();
myDate.setFullYear(2010,0,14);
var today = new Date();

if (myDate>today)
  {
  alert("Today is before 14th January 2010");
  }
else
  {
  alert("Today is after 14th January 2010");
  }

see this link.


or

you can write above php code in javascript . and remove echo's in if and else condition write alert boxs.

0

Hi,

If i use the php code in javascript, where do i insert the code?

thanx

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.