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)

		alert('Select the Start Date');
		return false;
		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...

Recommended Answers

All 5 Replies

Hellooo, some1 PLZ HELP!!!

do like this.

$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();
var today = new Date();

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

see this link.


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


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


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.