Hi ppl,

I have a form with a drop down box and a calendar picker.

I want to check if both these fields have been filled to proceed to the next page.

echo "<select name=Project value =' '>ProjectName</option>";
echo "<option>Select Project</option>";

while ($row=mysql_fetch_array($result)) { 

    echo "<OPTION VALUE=$row[Project_Id]>$row[ProjectName]</option>";
    } 
echo"</select>";
?></td>
<tr><td>Start Date:</td>
<td><?php
$myCalendar = new tc_calendar("date5", true, false);
$myCalendar->setIcon("calendar/images/iconCalendar.gif");
$myCalendar->setPath("calendar/");
$myCalendar->setYearInterval(2000, 2020);
$myCalendar->dateAllow('2008-05-13', '2010-03-01');
$myCalendar->setDateFormat('j F Y'); 
$myCalendar->writeScript(); 
?></td>

my javascript to select if the fields are selected is

function validateform(form1)
{

	if(form1.Project.value.length==0)
	{
	    alert('You have not selected any Project');
	    form1.focus();
		return false;
	}

	else if(form1.date5.value.length==0)
	{
		alert('Select the Start Date');
		form1.focus();
		return false;
	}
}

This code gives the message when the project field is not selected but not when the date is not selected.

HELP PLZ

Hi,

The problem is, if I don't select any date in the date field the form action is activated.

When I click the submit button without the date picked from the calendar, I want to show the user that he has not filled in...

HOW TO DO THIS?????

try following code in your validation function

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

Hi,

I tried ur code, still the forms action is activated...

But when I try something like this:

else if(form1.date5.value=='0000-00-00'.length==0)
	{
		alert('Select the Start Date');
		form1.focus();
		return false;
	}

The message box comes up, still there is a Problem....

The Problem is even after I select a date, the message box comes up saying that i have not filled....

Do you have any idea where I am wrong...

Thanx

try following code in your validation function

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

You use my code, It is correct version.
You simply remove form1.focus(); line from your function. You can not focus on any form.

WOW!!! THANX!!!!

S it WORKED!!! I removed the focus function... and it worked

BRILLIANT

THANK YOU:)

You use my code, It is correct version.
You simply remove form1.focus(); line from your function. You can not focus on any form.

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.