0

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

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

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

0

try following code in your validation function

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

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;	
}
0

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

Edited by urtrivedi: n/a

0

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.

This question has already been answered. 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.