enable onclick in the Select of a form

Asked

Viewed 675 times

2

I need to do that by clicking on select popup but it is not working, already the input works normally

$("#alert_button").click( function() {
jAlert('Selecione Primeiro o Estado', 'Classificados Publico');
});

<input id="alert_button" type="button" value="Show Alert" />

<select id="alert_button">
<option value="index.php?s=<?php echo "$termo"; ?>" selected> Cidade </option>
</select>

1 answer

2


Arsom, you have two elements with the same ID.
Ids must be unique. Switch to classes and it will work.

jQuery

$(".alert_button").click( function() {
    jAlert('Selecione Primeiro o Estado', 'Classificados Publico');
});

HTML

<input class="alert_button" type="button" value="Show Alert" />

<select class="alert_button">
    <option value="index.php?s=<?php echo "$termo"; ?>" selected> Cidade </option>
</select>

$(".alert_button").click( function() {
    alert('Selecione Primeiro o Estado');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<input class="alert_button" type="button" value="Show Alert" />
<select class="alert_button">
   <option value="index.php?s=termo" selected> Cidade </option>
</select>

Browser other questions tagged

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