I have a form which contains a select
, to be able to filter by higher or lower price, when I select an option if it performs filtering, the problem is that the select
never changes the option always stays in the first option.
I think it has to do something with the selected= "selected"
attribute, I've tried it in the following way but it has not worked, and I've even tried to put .atrr('selected', true)
from JQuery , but when I try this does not respect the instruction $("#search_form").submit();
Another thing for the front use materializecss
------------------- HTML -----------------
<form method="get" id="search_form"><!--Formulario para filtros-->
<select name="prices" id="price">
<option value="ASC"<?php
if (isset($_GET['prices'])
&& $_GET['prices'] == 'ASC') {
$selected = ' selected="selected"';
}
?> <?php $selected?>>ASC</option>
<option value="DESC"<?php
if (isset($_GET['prices'])
&& $_GET['prices'] == 'DESC') {
$selected = ' selected="selected"';
}
?> <?php $selected?>>DESC</option>
</select>
<label>Ordena Por:</label>
-------------------- JQuery -------------------------- --------
$('select#price').change(function(){
$("#search_form").submit();
return false;
});
------------------ PHP ---------------------------- ------------
if(isset($_GET['prices']) && $_GET['prices']!="") :
if($_GET['prices']=='ASC'):
$sql .= " ORDER BY precio ASC";
elseif($_GET['prices']=='DESC'):
$sql .=" ORDER BY precio DESC";
endif;
endif;