Lisa23 Posted April 27, 2012 Share Posted April 27, 2012 Hi i am trying to change the query to sort by desc or asc I am using the switch method but the form is not calling the switch statment can someone help me out please? this is the swicth script switch ($sortby) { case "ASC": $args = array( 's' => $_GET['s'], 'post_type' => 'deals', 'orderby' => 'title', 'order' => 'ASC', 'paged' => get_query_var('paged') ); break; case "DESC": $args = array( 's' => $_GET['s'], 'post_type' => 'deals', 'orderby' => 'title', 'order' => 'DESC', 'paged' => get_query_var('paged') ); break; } This is the form <form name="myForm"> <select id="sortby" > <option value="ASC">ASC</option> <option value="DESC">DESC</option> </select> </form> I intend to use a onchange so that when depending on the option they select it will change the order? Quote Link to comment https://forums.phpfreaks.com/topic/261694-hw-can-i-get-drop-down-form-to-change-sort-by-form-asc-or-desc/ Share on other sites More sharing options...
scootstah Posted April 27, 2012 Share Posted April 27, 2012 You would have to actually submit the form and then use the value of $_POST['sortby'] (note you'll need to give your select a name attribute) for your switch statement. If you want to use the onchange event or otherwise do it without actually submitting the form you will have to use Javascript. Quote Link to comment https://forums.phpfreaks.com/topic/261694-hw-can-i-get-drop-down-form-to-change-sort-by-form-asc-or-desc/#findComment-1341083 Share on other sites More sharing options...
Lisa23 Posted April 27, 2012 Author Share Posted April 27, 2012 Hi thanks for getting back at me I managed to get it to work like this. The script switch ($_POST['sortby']) { case "ASC": $args = array( 's' => $_GET['s'], 'post_type' => 'deals', 'orderby' => 'title', 'order' => 'ASC', 'paged' => get_query_var('paged') ); break; case "DESC": $args = array( 's' => $_GET['s'], 'post_type' => 'deals', 'orderby' => 'title', 'order' => 'DESC', 'paged' => get_query_var('paged') ); break; } The form <form method="post"> <select name="sortby" onChange="this.submit()"> <option value="">Sort By</option> <option value="DESC">DESC</option> <option value="ASC">ASC</option> </select> <input type="submit" value="submit"> </form> But now i am trying to change the form without the submit button just with the onchange. but is not working? Quote Link to comment https://forums.phpfreaks.com/topic/261694-hw-can-i-get-drop-down-form-to-change-sort-by-form-asc-or-desc/#findComment-1341088 Share on other sites More sharing options...
batwimp Posted April 27, 2012 Share Posted April 27, 2012 This this: <select name="sortby" onChange="this.form.submit()"> Quote Link to comment https://forums.phpfreaks.com/topic/261694-hw-can-i-get-drop-down-form-to-change-sort-by-form-asc-or-desc/#findComment-1341117 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.