I have a form with drop down lists and I want to clear after I submit it and it shows the table. I searched for clearing a form and I found to use javascript. I read this article how to clear a form. I wrote the following javascript code, but it doesn't work.
myjavascript.js
<script type="text/javascript">
<!--clear function-->
function resetForm(form){
// clearing selects
var selects = form.getElementsByTagName('select');
for (var i = 0; i<selects.length; i++)
selects[i].selectedIndex = 0;
return false;
}
</script>
This is my form:
principal.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
switch ($_POST['program']){
case 'BSc Computer Science':
include 'csreadprog.php';
break;
case 'BSc Psychology':
include 'psyreadprog.php';
break;
case 'BA Business Administration':
include 'baedreadprog.php';
break;
}
switch ($_POST['services']){
case 'Library':
include 'libraryread.php';
break;
case 'IT Services and Facilities':
include'itserviceread.php';
break;
case 'Front Desk':
include'frontdeskread.php';
break;
case 'Course Administrator':
include'courseadminread.php';
break;
case 'International Student Office':
include'stofficeread.php';
break;
case 'Clubs and Societies':
include'clubsread.php';
break;
}
switch($_POST['program'] && $_POST['criteria']){
case 'BSc Computer Science' && 'I have found the unit interesting':
include 'readcsprogcrit.php';
break;
case 'BSc Psychology' && 'I have gained knowledge':
include 'readpsyprogcrit.php';
break;
case 'BA Business Administration' && 'I have acquired skills':
include 'readbaedprogcrit.php';
break;
}
switch($_POST['year']){
case 'BSc Computer Science' && '2005':
include 'readcsprogyear.php';
break;
case 'BSc Psychology' && '2005':
include 'readpsyprogyear.php';
break;
case 'BA Business Administration' && '2005':
include 'readbaedprogyear.php';
break;
}
exit;
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="myjavascript.js"></script>
</head>
<body>
<div class="nav">
<ul>
<li><a href="principal.php">Principal</a></li>
<li><a href="acad_director.php">Academic Director</a></li>
<li><a href="lecturer.php">Lecturer</a></li>
</ul>
</div>
<form method="POST" action="principal.php" name="myform">
<b>Programs:<b/>
<select name="program">
<option value="Choose">Please select..</option>
<option value="Computer Science"> BSc Computer Science</option>
<option value="BAED">BA Business Administration</option>
<option value="Psychology">BSc Psychology</option></select><br/><br/>
<b>Departments:<b/>
<select name="department">
<option value="Choose">Please select..</option>
<option value="Computer Science">Computer Science</option>
<option value="BAED">BAED</option>
<option value="Psychology">Psychology</option></select><br/><br/>
<b>Year:<b/>
<select name="year">
<option value="Choose">Please select..</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option></select><br/><br/>
<b>Criteria:<b/>
<select name="criteria">
<option value="Choose">Please select..</option>
<option value="I have found the unit interesting">I have found the unit interesting</option>
<option value="I have gained knowledge">I have gained knowledge</option>
<option value="I have acquired skills">I have acquired skills</option>
<option value="Useful other resources">Useful other resources</option></select><br/><br/>
<b>Services:<b/>
<select name="services">
<option value="Choose">Please select..</option>
<option value="Library">Library</option>
<option value="Course Administrator">Course Administrator</option>
<option value="International Student Office">International Student Office</option>
<option value="IT Services and Facilities">IT Services and Facilities</option>
<option value="Front Desk">Front Desk</option>
<option value="Clubs and Societies">Clubs and Societies</option></select><br/><br/>
<br/>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Clear">
</form>