Hi folks,

Thanks for stopping by to read this. I'd be grateful for whatever help you can give me.

Being aware of the importance of making sure form checks are done server side, as well as client side, I was trying to implement the check of a drop down box.

E.G in HTML (menu.html)

<form action="fruitloop.php" method="POST" onsubmit="return checkform(this);"><p>

<select name="fruit">
<option value="choose" selected="selected">Choose an option
<option value="oranges">oranges
<option value="apples">apples
<option value="bananas">bananas
<input type="Submit" value="Eat!"/>

Checking client side in Java script:

<script language="JavaScript" type="text/javascript">
function checkform ( form )

// ** START **
if (form.fruit.selectedIndex == 0 ) {
alert( "Please choose a fruit." );
return false ;
// ** END **

return true ;


Which is fine because if I don't select a fruit it will tell me to do so.

But what about in PHP if they have disabled J script?

Checking server side in PHP (fruitloop.php):

I know that the !isset command should be used, and I understand how to implement it with a normal field, but can anyone tell me how to implement it with a drop down box?


//Take variable from submitted form

$fruit = $_POST['fruit'];

//start form checker

if (!isset($fruit)) {

header( "Location: http://www.fictionalwebsite.com/error.html" );
echo "Please choose a fruit<p>";
echo "Click on your browswer back button to return to form";


//If they try to access script on it's own without going through menu
//send them to menu.html -- is this correct?

else (empty($fruit) ) {
header( "Location: http://www.fictionalwebsite.com/menu.html" );


So as you can see I need PHP to work out when the value hasn't been selected and also when they haven't even viewed my form, and are just trying to access the script by itself, in reference to the drop down box.

I could use an If statement or a switch statement, but that seems to me a long way round the houses, and it would be good to know how to use "!isset"
and "empty" with this.

Thanks very much,