here is my js code
<script type="text/javascript">
function resetForm(formID)
{
var myForm = document.getElementById(formID);
for (var i = 0; i < myForm.elements.length; i++)
{
if ('submit' != myForm.elements[i].type && 'reset' != myForm.elements[i].type)
{
myForm.elements[i].checked = false;
myForm.elements[i].value = '';
myForm.elements[i].selectedIndex = 0;
}
}
}
</script>
here is my php code,
echo "<form class='navbar-form' id='formID' method='POST' action=''>";
$sqluser="SELECT DISTINCT username FROM user ORDER BY username ASC";
$resultuser=mysqli_query($conn,$sqluser);
if(isset($_POST['from_date']))
echo "<div class='form-group' style='margin-right:5px;'><input id='from_date' name='from_date' type='date' data-date-inline-picker='true' value='".$_POST['from_date']."'/></div>";
else
echo "<div class='form-group' style='margin-right:5px;'><input id='from_date' name='from_date' type='date' data-date-inline-picker='true' /></div>";
if(isset($_POST['from_date']))
echo "<div class='form-group' style='margin-right:5px;'><input id='to_date' name='to_date' type='date' data-date-inline-picker='true' value='".$_POST['to_date']."'/></div>";
else
echo "<div class='form-group' style='margin-right:5px;'><input id='to_date' name='to_date' type='date' data-date-inline-picker='true' /></div>";
echo "<div class='form-group' style='margin-right:5px;'><select id='username' name='username' style='width:170px;height:33px;'>";
if(isset($_POST['username']) && $_POST['username'] == "-- Username --")
echo "<option selected='selected'>-- Username --</option>";
else
echo "<option >-- Username --</option>";
while($ro1=mysqli_fetch_array($resultuser))
{
if(isset($_POST['username']) && $_POST['username'] == $ro1['username'])
echo "<option selected='selected' value='".$ro1['username']."'>".$ro1['username']."</option>";
else
echo "<option value='".$ro1['username']."'>".$ro1['username']."</option>";
}
echo "</select>";
echo "</div>";
echo "<div class='form-group' style='margin-right:5px;'><input name='reset' type='reset' onclick='resetForm('formId'); return false;' /></div>";
echo "<div class='form-group' style='margin-right:5px;'><input type='submit' value='submit'></div>";
echo "</form>";
on clicking the submit button, the form is submitted to the same page and result will be displayed below the form. i'm displaying the user inout values in the form , even after submitting. now,i want a reset button to clear all the input fields.after submitting the form, but the reset button is working before submission and it isn't working after submission.