hey all

i need to check to see if my check box is checked, here is my code...

echo "<form id='form1' name='form1' method='post' action='".$href."' onsubmit='return checked_room()'>";		
		
		while($row = mysql_fetch_assoc($res))
		{			
			$roomName = $row['RoomName'];
			
			if(!in_array($roomName,$taken_array)){
			
				echo "<div id='RoomBorder'>";
				echo "<table width='100%'><tr><th colspan='2'>". $row['RoomName'] ."</th></tr>";
				echo "<tr><td colspan='2' align='left'>".$row['RoomDescription']."</td></tr>";
				echo "<tr><td><b>Max Guests ".$row['RoomCapacity']."</b></td><td><b>Rates</b></td></tr>";
				echo "<tr><td></td><td>".SeasonPrice($roomName)."</td></tr>";
				echo "<tr><td>Select desired room:<input type='checkbox' name='SelectRoom[]' value='".$row['RoomName']."'/></td><td align='Left'>";
				
				echo "<input type='submit' name='Next' id='Next' value='Next' /></td></tr>";
				echo "</table><br><br>";
				echo "</div><br>";
			}
			
		}
		
		//<!--End of div RoomBorder-->
		echo "</form>";

--------
my validation
---

function checked_room()
{
	if(empty($box))
	{
		echo "You need to check a room inorder to book!";
		return false;
	}
	else
	{
		return true;
	}
}

now for some reason i can't get the javascript to work within the function.

does anyone know what's going on??

shot

"echo" is not a JavaScript function but it is PHP. Is this code in PHP?

Hey try this one,

<script type="text/javascript">
function checked_room() {

   // if the check box is not an array use this
   if (!document.form1.SelectRoom.checked) {
      alert("You need to check a room inorder to book!"); 
      return false; 
   } else {
      return true;
   }

   // if the check box is an array use this one
   var error == '';
   for (var i=0; i < document.form1.SelectRoom.length; i++) {
      if (!document.form1.SelectRoom[i].checked)
        error +=document.form1.SelectRoom[i].value + "\n"
   }
   if(error != "")
     alert(error + "You need to check these room inorder to book!");
     return false;
   else 
     return true;
}
</script>

Hope this will help you :)

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.