I use this because I'm developing an E-Commercer system, but the client wants the products to be in ComboBox with Select. Until then everything is correct, my difficulty is to make the change to the URL, according to the 'product' selected in <SELECT>/<OPTION>
I need the URL to be changed according to the items selected in Select, this Select makes a query in the database that presents the products in the
I'm getting the information when I choose the given SELECT OPTION: My problem is changing the URL.
Follow the Code.
// I get the OPTION values and change to a variable.
echo "<script language='javascript'>
function PegarValores(){
pd_nome = document.getElementById('produto_nome').options[document.getElementById('produto_nome').selectedIndex].text;
pd_id = document.getElementById('produto_nome').value;
alert(pd_id+' - '+pd_nome);
}
</script>";
Alert is correctly retrieving the values of the selected select.
The problem now comes up, how to make the URL automatically change according to the value selected in the select.
echo "<select id='produto_nome' name='produto_nome[]' value='' onchange='PegarValores()'>
<option value='-1'>
Selecione
</option>";
while ($proteina = mysqli_fetch_assoc($query)){
extract($proteina);
echo '<option value="' . $produto_id . '">' . $produto_nome . '</option>';
}
echo "</select>";
echo "<a href='addtocart.php?id='$produto_id&name=$produto_nome' class='customButton'>";
echo "Adicionar";
echo "</a>";