Run javascript by clicking on combobox

Asked

Viewed 111 times

3

Is there any way when you have with a combobox open run a script?

  • 1

    if that’s what I wanted.

  • you can use the click event for this, http://jsfiddle.net/4fLb5bqo/

1 answer

3


The event of click you can implement as follows:

document.getElementById("combobox").addEventListener("click", eventoClick);

function eventoClick() {
    alert("teste do onclick")
}

There is also the event of change which is when the combobox options are toggled:

document.getElementById("combobox").addEventListener("change", eventoClick); 

function eventoChange(){
        alert("teste do change")
}

And also the mouseover:

document.getElementById("combobox").addEventListener("mouseover", eventoMouseOver);

function eventoMouseOver() {
    alert("teste do mouseover")
}

Follows the jsfiddle

  • Thanks :), there is also some way when you go over option run also another script?

  • $("select option").hover(function() {
 alert("ola");
 }); I did so but this not to give.

  • I updated the post and jsfiddle =D

Browser other questions tagged

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