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...

Hellooo, some1 PLZ HELP!!!

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.

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.

Hi,

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

thanx

Be a part of the DaniWeb community

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