Hi. Ive been trying to use an untested function that Justin Johnson coded(thanks again mate), but ive been struggling with IE errors. Im a begginner in javascript.
Basically what happens is this:
- User chooses an option from a select box.
- Other corresponding select box becomes visible.
- If there is any other select box that was choosed earlier, hide it.
Everything is ok in Firefox. I change the select box and everything works. But when i try to use in IE7/8 it doesnt change nothing!
I used the option9.style.cssText='display: none';
instead of the option2.style.display = "none";
but it doesnt work either.
Here is the code(not all the select cases are in this code, for reading purpose and the code needs optimization, i will do it later on):
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);
}
};
// Once the window loads and the DOM is ready, attach the event to the main
attachEvento(window, "load", function() {
var main_select = document.getElementById("tipos_evento");
var option1 = document.getElementById("temas_conferencias"),
option2 = document.getElementById("temas_cursos"),
option3 = document.getElementById("temas_provas"),
option4 = document.getElementById("temas_visitas"),
option5 = document.getElementById("temas_ciencias"),
option6 = document.getElementById("temas_dancas"),
option7 = document.getElementById("temas_exposicoes"),
option8 = document.getElementById("temas_multi"),
option9 = document.getElementById("temas_musica"),
option10 = document.getElementById("temas_teatro"),
option11 = document.getElementById("temas_cultura"),
option12 = document.getElementById("temas_desporto"),
option13 = document.getElementById("temas_todos");
//initialize with all the select boxes hidden except one
option1.style.cssText='display: none';
option2.style.cssText='display: none';
option3.style.cssText='display: none';
option4.style.cssText='display: none';
option5.style.cssText='display: none';
option6.style.cssText='display: none';
option7.style.cssText='display: none';
option8.style.cssText='display: none';
option9.style.cssText='display: none';
option10.style.cssText='display: none';
option11.style.cssText='display: none';
option12.style.cssText='display: none';
option13.style.cssText='display: block';
var selectHandler = function() {
// Show and hide the appropriate select's
switch(this.value) {
case "8":
// Conferências / colóquios
option1.style.display = "block";
option2.style.display = "none";
option3.style.display = "none";
option4.style.display = "none";
option5.style.display = "none";
option6.style.display = "none";
option7.style.display = "none";
option8.style.display = "none";
option9.style.display = "none";
option10.style.display = "none";
option11.style.display = "none";
option12.style.display = "none";
option13.style.display = "none";
break;
case "10":
// Cursos/workshops
option1.style.cssText='display: none';
option2.style.cssText='display: block';
option3.style.cssText='display: none';
option4.style.cssText='display: none';
option5.style.cssText='display: none';
option6.style.cssText='display: none';
option7.style.cssText='display: none';
option8.style.cssText='display: none';
option9.style.cssText='display: none';
option10.style.cssText='display: none';
option11.style.cssText='display: none';
option12.style.cssText='display: none';
option13.style.cssText='display: none';
break;
case "7":
// provas
option1.style.cssText='display: none';
option2.style.cssText='display: none';
option3.style.cssText='display: block';
option4.style.cssText='display: none';
option5.style.cssText='display: none';
option6.style.cssText='display: none';
option7.style.cssText='display: none';
option8.style.cssText='display: none';
option9.style.cssText='display: none';
option10.style.cssText='display: none';
option11.style.cssText='display: none';
option12.style.cssText='display: none';
option13.style.cssText='display: none';
break;
case "12":
// ciencia
option1.style.cssText='display: none';
option2.style.cssText='display: none';
option3.style.cssText='display: none';
option4.style.cssText='display: none';
option5.style.cssText='display: block';
option6.style.cssText='display: none';
option7.style.cssText='display: none';
option8.style.cssText='display: none';
option9.style.cssText='display: none';
option10.style.cssText='display: none';
option11.style.cssText='display: none';
option12.style.cssText='display: none';
option13.style.cssText='display: none';
break;
default:
// Hide all
option1.style.cssText='display: none';
option2.style.cssText='display: none';
option3.style.cssText='display: none';
option4.style.cssText='display: none';
option5.style.cssText='display: none';
option6.style.cssText='display: none';
option7.style.cssText='display: none';
option8.style.cssText='display: none';
option9.style.cssText='display: none';
option10.style.cssText='display: none';
option11.style.cssText='display: none';
option13.style.cssText='display: block';
}
};
// 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);
});
Thank u.
Here is the HTML.
<div class="pesquisa-event-select"><!-- pesquisa select-boxs -->
<p>
<label for="tipo">tipo de evento </label>
<select id="tipos_evento">
<option value="104">todos</option>
<option value="8">Conferências/Colóquios</option>
<option value="10">Cursos/Workshops</option>
<option value="7">Provas académicas</option>
<option value="9">Visitas/Observações</option>
<option value="12">Ciência(outros)</option>
<option value="2">Danças</option>
<option value="1">Exposições</option>
<option value="3">Multidisciplinar</option>
<option value="4">Música</option>
<option value="5">Teatro</option>
<option value="6">Cultura(outros)</option>
<option value="48">Desporto</option>
</select>
</p>
<div id="temas_todos">
<p>
<label for="Tema">tema de evento </label>
<select>
<option value="">todos</option>
<xsl:for-each select="temas_todos/TemasEventos/Row">
<xsl:sort select="TipoEvento"/>
<option value="{Numero}">
<xsl:value-of select="TipoEvento" />_
<xsl:value-of select="TemaEvento" />
</option>
</xsl:for-each>
</select>
</p>
</div>
<div id="temas_conferencias">
<p>
<label for="Tema">tema de evento</label>
<select>
<option value="">todos</option>
<xsl:for-each select="temas_conferencias/TemasEventos/Row">
<xsl:sort select="TemaEvento"/>
<option value="{Numero}">
<xsl:value-of select="TemaEvento" />
</option>
</xsl:for-each>
</select>
</p>
</div>
<div id="temas_cursos">
<p>
<label for="Tema">tema de evento</label>
<select>
<option value="">todos</option>
<xsl:for-each select="temas_cursos/TemasEventos/Row">
<xsl:sort select="TemaEvento"/>
<option value="{Numero}">
<xsl:value-of select="TemaEvento" />
</option>
</xsl:for-each>
</select>
</p>
</div>