Problem in combobox

Hi, from this page, top right field “Digita o seleziona la biblioteca” I have this script that, when I click on that field, correctly sets the default option value to Municipio X > Morante (with two consecutive autoclicks). But when I change the value of the combobox on the left from “Catalogo” to “Libri moderni” it stops running. Could you help me to solve? Thank you!

Seems to work fine for me! What browser are you using?

Thanks for the answer, ralphm. I’m using Chrome browser v. 114. It works if you first of all click on top right field Digita o seleziona la biblioteca, it doesn’t work if the first action is changing the option value of the combobox on the left from Catalogo to Libri moderni, then you click on top right field.

1 Like

Hm, it works for me in various browsers (including Chrome on macOS), even if I choose the left option first.

Event delegation.

Changing the left combobox recreates the right combobox, obliterating the event listener that the script attached.

Thanks, m_hutley, so nothing could be done?

This i did not say. You’ll have to delegate the event, is all.

In vanilla Javascript, this can be done by changing 3 lines in the script. (well, changing 2 and adding a third)

    var inputField = document.querySelector("#bibliosel2");
    inputField.addEventListener("click", function() {

=>

    var inputField = document.querySelector("#pagesearch");
    inputField.addEventListener("click", function(e) {
        if(e.target.id !== "bibliosel2") { return; }
2 Likes

Thanks, m_hutley, it works great now!!!

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.