Retain dropdown select search selection onChange

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 23, 2019   (RSS)

By Mikey - January 18, 2019

Howdy folks,

I'm stumped on a dropdown selector feature. I have a form that has three fields.

  • One for a "text" keyword search.
  • Second for a dropdown "select" document_category search match.
  • and a third for a dropdown "select" year search match.

These work individually, however they do not to together because of the onChange="this.form.submit();" feature. So I can search using each field, but I can not drill down with more in-depth searches, because each time the page loads the selection for onChange="this.form.submit();" the previous selection made is lost.

I would like for each selection to be retained once the page has refresh using onChange="this.form.submit();" so that I can begin searching by keyword and continue drilling down for records by selecting a category, and if needed drill even further down I can using the year dropdown selector.

I really don't know how to accomplish this, but below is my code with an example written as IF SELECTED <?php echo "selected"; ?> END IF that shows what I'm trying to do. I'm sure there are better ways to accomplish the same results... so I'm open to any suggestions.

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" >

<input name="title,content_keyword" type="text" value="<?php echo htmlspecialchars(@$_REQUEST['title,content_keyword']); ?>" placeholder="Keyword" />
        
  			<select name="document_category_match" onChange="this.form.submit();">
     			<option value="">Categories</option>
      				<?php foreach ($documentCatArray as $value => $label): ?> 
      			<option value="<?php echo $value; ?>" <?php selectedIf($value, @$_REQUEST['document_category']) ?> IF SELECTED <?php echo "selected"; ?> END IF ><?php echo $label; ?></option>
      				<?php endforeach ?>
    		</select>
        
 			<select name="date_year" onChange="this.form.submit();" >
      			<option value="">Year</option>
      				<?php foreach($years as $year):?> 
     					<option value="<?php echo $year;?>" IF SELECTED <?php echo "selected"; ?> END IF ><?php echo $year;?></option> 
    				<?php endforeach ?>
    		</select>
       
			<input type="submit" name="submit2" value="Search"/>
        
	</form>

Thanks, Zick

By Mikey - January 23, 2019

Thanks for your guidance on this Daniel!

Your suggestions/solution got me headed in the right direction and everything works like a charm now!

Cheers, Zicky