How to do OnClick action in Select Option [closed]

0

I need to do an onclick action on each option of a select with a different link according to each id, but it is not working.

$label .= "<select size=\"1\" name=\"modulo\" class='form-control'";

$label .= "<option value=\"0\" selected=\"selected\" onclick=\"javascript:document.location.href='admin_solicitacoes.php?DfStatus=$DfStatus&modulo=0&desenvolvimento=$desenvolvimento&tipo=$tipo&plataforma=$plataforma'\">Todos</option>";

$sql_buscar_modulo = "SELECT DfIdModulo, DfDescricao FROM $tbModulo ORDER BY DfDescricao ASC";
$resultado_buscar_modulo = mysql_query($sql_buscar_modulo)
or die ("$mysql_erro");

while ($linha=mysql_fetch_array($resultado_buscar_modulo)) {
    $DfIdModulo = $linha["DfIdModulo"];
    $DfDescricao = stripslashes($linha["DfDescricao"]);

    $label .= "<option value=\"$DfIdModulo\" onclick=\"javascript:document.location.href='admin_solicitacoes.php?DfStatus=$DfStatus&modulo=$DfIdModulo&desenvolvimento=$desenvolvimento&tipo=$tipo&plataforma=$plataforma'\">$DfDescricao</option>";
}

$label .= "</select>";
    
asked by anonymous 05.02.2018 / 12:54

1 answer

1

To handle redirects in Selector you can use the onChange event for this, see:

 document.getElementById("selector").onchange = function(){
      location.href = this.value;
    }
<select id="selector">
    <option value="https://wwww.facebook.com.br/">Facebook</option>
    <option value="https://wwww.google.com.br/">Google</option>
    <option value="https://wwww.youtube.com/">Youtube</option>
  </select>
 

If I helped you, do not forget to leave the vote! ^.

    
05.02.2018 / 18:51