Jump to content

[SOLVED] Reset dynamic search form


pikemsu28

Recommended Posts

ok, i'm tired of trying to figure this out on my own so i need some help from you guys/gals!!

 

i have a search form that has a set of checkboxes and a set of select boxes.  the checkboxes correspond to a select box and activates the select box once checked.  when i submit the search form to display the results on the same page, the elements are echoed back into the form so the user can see what search criteria he/she search for:

 

<?php
$year = date("Y");
$year1 = date("Y")+1;
$year2 = date("Y")+2;
?>
<script language="javascript">
function enable(radiocontrol, forselectID)
{
if (document.forms["search"].elements[radiocontrol].checked == true) 
{ 
	document.forms["search"].elements[forselectID].disabled = false; 
} else {
	document.forms["search"].elements[forselectID].disabled = true;
}
}

</script>
<form id="search" name="search" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<input onClick="enable('semfall', 'semfallyear')" name="semfall" id="semfall" type="checkbox" class="checkbox" value="Fall" <?php if(isset($_POST['semfall'])){if($_POST['semfall'] == 'Fall'){echo 'checked="checked"';}}?> /><label for="Fall">Fall</label>
<select class="small" name="semfallyear" id="semfallyear" <?php if(!isset($_POST['semfall'])){echo "disabled=\"disabled\"";}?>>
  <option selected="selected" value="">Select</option>
  <option <?php if(isset($_POST['semfallyear'])){if($_POST['semfallyear'] == $year){echo "selected=\"selected\"";}} ?> value="<?php echo $year;?>"><?php echo $year;?></option>
  <option <?php if(isset($_POST['semfallyear'])){if($_POST['semfallyear'] == $year1){echo "selected=\"selected\"";}} ?> value="<?php echo $year1;?>"><?php echo $year1;?></option>
  <option <?php if(isset($_POST['semfallyear'])){if($_POST['semfallyear'] == $year2){echo "selected=\"selected\"";}} ?> value="<?php echo $year2;?>"><?php echo $year2;?></option>
</select>
<input id="reset" name="reset" type="reset" value="Reset"/>
<input id="search" name="search" type="submit" value="Search" />
</form>

 

the problem is, where i'm echoing the checked="checked" for the checkbox back into the form, when the reset button is clicked the select boxes reset but my checkboxes stay checked.  i've searched for javascript/php to reset the checkboxes but have came up empty handed.  anyone have a good suggestion or can point me in the direction of the answer?  anything at this point would greatly be appreciated!!

 

thanks,

Jason

Link to comment
https://forums.phpfreaks.com/topic/46474-solved-reset-dynamic-search-form/
Share on other sites

I have also run into the same problem. Try adding a function to your reset button that refreshes the page or send it to the same page without posting any variables. That's what I had to do.

 

EX:

/page.php?register shows a register form. ONce they submit it, it takes them to /page.php?submitform, but if there are errors it stay on /page.php?submitform with some error messages. I added a function to the reset button to go back to /page.php?register without reposting any of the input variables that they already filled in.

 

Does that make sense? If not, PM me. That's just how I did it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.