In my code below I have 2 drop down menus. One is a \"Course\" drop down menu and the other is a \"Modules\" drop down menu:
Below is the code:
You can do this using javascript create a function inside it where you can check weather each field is filled or not can be displayed there like this
<script type="text/javascript">
function validate()
{
if(document.dropdownmenuname.course.value=="")
{
alert("Please fill in your form");
document.dropdownmenuname.course.focus() ;
return false;
}
}
....
Change your form tag
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
to
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return validation();">
It's a good idea to validate on serverside too, just add a little code in your existing PHP if you want to check values on serverside:
<?php
if (isset($_POST['moduleSubmit'])) {
if(empty($_POST['courses']) && empty($_POST['modules'])) {
echo 'Please Select a Course and Module';
} elseif(empty($_POST['courses'])) {
echo 'Please Select a Course';
} elseif(empty($_POST['modules'])) {
echo 'Please Select a module';
} else {
$sessionquery = "
SELECT SessionId, SessionDate, SessionTime, ModuleId, TeacherId
FROM Session
WHERE
(ModuleId = ? AND TeacherId = ?)
ORDER BY SessionDate, SessionTime
";
$sessionqrystmt=$mysqli->prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt->bind_param("si",$moduleId,$userid);
// get result and assign variables (prefix with db)
$sessionqrystmt->execute();
$sessionqrystmt->bind_result($dbSessionId,$dbSessionDate,$dbSessionTime, $dbModuleId, $dbTeacherId);
$sessionqrystmt->store_result();
$sessionnum = $sessionqrystmt->num_rows();
if($sessionnum ==0){
echo "<p>Sorry, You have No Sessions under this Module</p>";
}