activate onclick on the Select of a form

2

I need to do that with clicking select select popup but it is not working, 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>
    
asked by anonymous 15.10.2014 / 01:27

1 answer

2

Arsom, you have two elements with the same ID.
IDs must be unique . It changes to classes and 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><inputclass="alert_button" type="button" value="Show Alert" />
<select class="alert_button">
   <option value="index.php?s=termo" selected> Cidade </option>
</select>
    
15.10.2014 / 08:46