Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Not to bash the code you were provided... but there is likely a much cleaner way to implement this. (code untested)</p> <pre><code>var attachEvento = function(node, event, listener, useCapture) { // Method for FF, Opera, Chrome, Safari if (window.addEventListener ) { node.addEventListener(event, listener, useCapture || false); } // IE has its own method else { node.attachEvent('on'+event, listener); } }; var selectLists = ['temas_conferencias','temas_cursos','temas_provas','temas_visitas','temas_ciencias','temas_dancas','temas_exposicoes','temas_multi','temas_musica','temas_teatro','temas_cultura','temas_desporto','temas_todos']; var selectHandler = function(){ var value = this.value; var select; for(var i=0,sLen=selectLists.length;i&lt;sLen;i++){ select = document.getElementById(selectLists[i]); if(value == (i+1)){ select.style.display = 'block'; } else { select.style.display = 'none'; } } }; attachEvento(window, "load", function() { // Use the onchange and onkeypress events to detect when the // value of main_select has changed attachEvento(main_select, "change", selectHandler); attachEvento(main_select, "keypress", selectHandler); }); </code></pre> <p>Essentially it does this.</p> <ol> <li><p>It registers an event handler "selectHandler" for the onchange or onkeypress events on the main select list.</p></li> <li><p>To minimized the code, I've put the IDs of the "other" select lists into an array called "selectLists"</p></li> <li><p>When the selectHandler is triggered, it simply checks the value of the main select, then iterates over the other selects in the "selectLists" array and sets the display to "none" - unless it matches the main select value, in which case it displays it.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload