Chosen-select Onclik event

Asked

Viewed 30 times

0

Good Afternoon

Staff I am developing an application using Chosen-select in place of conventional select and I arose a need on the onclick event of that select below I made the following statement:

function teste() {
         alert('teste1');
       }
       
 $("#select").bind("click", function () {
        alert($(this).val());
       });       
<select id="select" data-placeholder="Informe o Usuário..." onkeyup="teste();" class="chosen-select" tabindex="2">
            <option onclick="teste();" value="00">Nenhum</option>
            <option onclick="teste();" value="01">Eder</option>
            <option onclick="teste();" value="02">Fabiano</option>
            <option onclick="teste();" value="03">Eduardo</option>    
    </select>   

The function test() is not executed in any way but the second routine is captured someone can explain to me why the function does not work?

1 answer

0

The tag option does not support the event onclick.

If you want access to value of option can use the event onchange on the tag select:

function teste(value){
  alert(value);
}
<select id="select" data-placeholder="Informe o Usuário..." onchange="teste(value);" class="chosen-select" tabindex="2">
  <option value="00">Nenhum</option>
  <option value="01">Eder</option>
  <option value="02">Fabiano</option>
  <option value="03">Eduardo</option>    
</select>  

Browser other questions tagged

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