designer76 Posted July 20, 2012 Share Posted July 20, 2012 Hi, I have this code 95% finished, and it is doing everything I that need it to except for one thing and I can't seem to figure it out. I am using the php at the very bottom of this code in conjunction with some code in a different document to hide certain dropdowns based on what option is selected in another dropdown. That part works perfectly fine, the only thing that I can't figure out is how to clear the value of the dropdown that is being hidden so that it doesn't effect the filter results while it is hidden (which it currently does now). For example: if (isset($_GET['category']) && $_GET['category']=='designs') { $hideme2 = "style='display: none'"; } I need the ['category']=='designs' part to be reset back to ['category']=='' when the dropdown gets hidden. That is all that I need to fix in order for things to work exactly like I need them to. Can anyone help me with this? I do want to state that there are other parts of this code in other documents that I didn't post because it would be way too long, and I don't think those parts effect this particular issue. I believe/hope that I have included all of the code necessary to fix the issue. Thanks in advance for any help given! <div class='filter_container'> <form action="" method="GET" name="filter" id="filter"> <input type="hidden" name="sale" value=""> <input type="hidden" name="page" value="1"> <div class="dropdown_headings"><p>Category:</p></div> <div class="dropdown_container"> <select name="category" class='filter_dropdowns' id="category" onchange="javascript:document.forms['filter'].submit();"> <option class='dropdown_options' value="" <?php if (isset($_GET['category']) && $_GET['category']=='') { echo 'selected'; } ?>>All Available</option> <option class='dropdown_options' value="designs" <?php if (isset($_GET['category']) && $_GET['category']=='designs') { echo 'selected'; } ?>>Designs</option> <option class='dropdown_options' value="paintings" <?php if (isset($_GET['category']) && $_GET['category']=='paintings') { echo 'selected'; } ?>>Paintings</option> <option class='dropdown_options' value="sketches" <?php if (isset($_GET['category']) && $_GET['category']=='sketches') { echo 'selected'; } ?>>Sketches</option> </select> </div> <div class="hideme1" <?php echo $hideme1 ?>> <div class="dropdown_headings"><p>Filter 1:</p></div> <div class="dropdown_container"> <select name="filter1" class='filter_dropdowns' id="filter1" onchange="javascript:document.forms['filter'].submit();"> <option class='dropdown_options' value="" <?php if (isset($_GET['filter1']) && $_GET['filter1']=='') { echo 'selected'; } ?>>All Designs</option> <option class='dropdown_options' value="ads" <?php if (isset($_GET['filter1']) && $_GET['filter1']=='ads') { echo 'selected'; } ?>>Ads</option> <option class='dropdown_options' value="brochures" <?php if (isset($_GET['filter1']) && $_GET['filter1']=='brochures') { echo 'selected'; } ?>>Brochures</option> </select> </div> </div> <div class="hideme2" <?php echo $hideme2 ?>> <div class="dropdown_headings"><p>Filter 2:</p></div> <div class="dropdown_container"> <select name="filter2" class='filter_dropdowns' id="filter2" onchange="javascript:document.forms['filter'].submit();"> <option class='dropdown_options' value="" <?php if (isset($_GET['filter2']) && $_GET['filter2']=='') { echo 'selected'; } ?>>All Paintings</option> <option class='dropdown_options' value="oil paintings" <?php if (isset($_GET['filter2']) && $_GET['filter2']=='oil paintings') { echo 'selected'; } ?>>Oil Paintings</option> <option class='dropdown_options' value="watercolors" <?php if (isset($_GET['filter2']) && $_GET['filter2']=='watercolors') { echo 'selected'; } ?>>Watercolors</option> </select> </div> </div> </div> <div class="dropdown_headings"><p>Sort By:</p></div> <div class="dropdown_container"> <select name="sortby" class='filter_dropdown' onchange="javascript:document.forms['filter'].submit();"> <option class='options_options' value="" <?php if (isset($_GET['sortby']) && $_GET['sortby']=='') { echo 'selected'; } ?>>All Available</option> <option class='options' value="featured artwork" <?php if (isset($_GET['sortby']) && $_GET['sortby']=='featured artwork') { echo 'selected'; } ?>>Featured Artwork</option> <option class='options' value="new artwork" <?php if (isset($_GET['sortby']) && $_GET['sortby']=='new artwork') { echo 'selected'; } ?>>New Artwork</option> </select> </div> </form> </div> <?php { if (isset($_GET['category']) && $_GET['category']=='designs') { $hideme2 = "style='display: none'"; } if (isset($_GET['filter1']) && $_GET['filter1']=='ads') { $hideme2 = "style='display: none'"; } if (isset($_GET['filter2']) && $_GET['filter2']=='oil paintings') { $hideme1 = "style='display: none'"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/265996-i-need-help-hiding-dropdowns-selects-used-to-sort-search-results/ Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Is this what you want? if (isset($_GET['category']) && $_GET['category']=='designs') { $hideme2 = "style='display: none'"; $_GET['category'] = ''; } You're being pretty vague in what you want to do exactly. 'When the dropdown gets hidden' doesn't happen until the client parses the page. This doesn't happen until all server-side code has already been executed, so I'm not sure if this is the desired effect. Quote Link to comment https://forums.phpfreaks.com/topic/265996-i-need-help-hiding-dropdowns-selects-used-to-sort-search-results/#findComment-1363062 Share on other sites More sharing options...
designer76 Posted July 20, 2012 Author Share Posted July 20, 2012 Is this what you want? if (isset($_GET['category']) && $_GET['category']=='designs') { $hideme2 = "style='display: none'"; $_GET['category'] = ''; } You're being pretty vague in what you want to do exactly. 'When the dropdown gets hidden' doesn't happen until the client parses the page. This doesn't happen until all server-side code has already been executed, so I'm not sure if this is the desired effect. I apologize for being vague, that wasn't my intent at all. That code looks exactly like what I am looking for, and I tried something similar but I think my formatting was incorrect. I will try this and report back to you. If it is not what I was looking for I will be happy to provide whatever extra details you may need to assist me. Quote Link to comment https://forums.phpfreaks.com/topic/265996-i-need-help-hiding-dropdowns-selects-used-to-sort-search-results/#findComment-1363070 Share on other sites More sharing options...
designer76 Posted July 20, 2012 Author Share Posted July 20, 2012 Is this what you want? if (isset($_GET['category']) && $_GET['category']=='designs') { $hideme2 = "style='display: none'"; $_GET['category'] = ''; } You're being pretty vague in what you want to do exactly. 'When the dropdown gets hidden' doesn't happen until the client parses the page. This doesn't happen until all server-side code has already been executed, so I'm not sure if this is the desired effect. This is exactly what I needed. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/265996-i-need-help-hiding-dropdowns-selects-used-to-sort-search-results/#findComment-1363087 Share on other sites More sharing options...
designer76 Posted July 20, 2012 Author Share Posted July 20, 2012 Actually, I may have been slightly premature. The code provided DOES clear out/reset the dropdown box value, the only problem is that the page url does not, and it is still sorting by the previous value in the hidden dropdown box. If I am not being clear enough or you need more info, please let me know. Basically I am half way there, I just need the url to update to reflect that there is no longer a value to sort by in the hidden box. Quote Link to comment https://forums.phpfreaks.com/topic/265996-i-need-help-hiding-dropdowns-selects-used-to-sort-search-results/#findComment-1363097 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 This is client-side behaviour. You can't change the browser's URI using PHP without reloading the page, which is undesired. You could do with with the new HTML5/JavaScript pushState, but that's not universally supported. Quote Link to comment https://forums.phpfreaks.com/topic/265996-i-need-help-hiding-dropdowns-selects-used-to-sort-search-results/#findComment-1363100 Share on other sites More sharing options...
designer76 Posted July 20, 2012 Author Share Posted July 20, 2012 This is client-side behaviour. You can't change the browser's URI using PHP without reloading the page, which is undesired. You could do with with the new HTML5/JavaScript pushState, but that's not universally supported. I am a little confused I guess, it works now just using PHP and Javascript. When you select a dropdown option, the page refreshes and shows/sorts the results based on the option you pick, and so on. This code below is what does it. javascript:document.forms['filter'].submit(); The only problem when I add the hiding dropdown and clearing hidden dropdown value is that the page refresh does not update the url and clear out the value of the hidden dropdown. I know there are more sophisticated ways to do something like this now, but I am somewhat new to this stuff and I am just looking to find something that works if possible. Quote Link to comment https://forums.phpfreaks.com/topic/265996-i-need-help-hiding-dropdowns-selects-used-to-sort-search-results/#findComment-1363116 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Try using the POST method, rather than the GET for your forms. Quote Link to comment https://forums.phpfreaks.com/topic/265996-i-need-help-hiding-dropdowns-selects-used-to-sort-search-results/#findComment-1363120 Share on other sites More sharing options...
designer76 Posted July 20, 2012 Author Share Posted July 20, 2012 Try using the POST method, rather than the GET for your forms. Unfortunately, still no luck. I don't get it, the dropdown selection is being changed to nothing when it is hidden, so I would think that on the page refresh the url would do the same thing. It seems like it would work like it has been except the only difference being that the dropdown is hidden now. It makes no sense why it doesn't work exactly as you typed out in your earlier post. Weird. Quote Link to comment https://forums.phpfreaks.com/topic/265996-i-need-help-hiding-dropdowns-selects-used-to-sort-search-results/#findComment-1363138 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.