How to do Onclick action in Select Option

Asked

Viewed 1,304 times

0

I need to do an onclick action on each option of a select with a different link according to the id of each, but it’s 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>";

1 answer

1


To handle redirects in Selector(select) 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/">Google</option>
    <option value="https://wwww.youtube.com/">Youtube</option>
  </select>
 

In case I helped you, don’t forget to leave the vote! ^.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.