ciao a tutti :
ho uno script che ha due comportamenti diversi in base al browser
su mozilla funziona mentre su IE no ....
function sezione(){
var oField=document.createElement("select");
oField.setAttribute("id","sel");
oField.setAttribute("name","sel");
if(navigator.appName!="Microsoft Internet Explorer")
{
var option=document.createElement("option");
var oText1=document.createTextNode("scegli:");
option.setAttribute("disabled", "disabled");
option.setAttribute("selected", "selected");
option.setAttribute("value", "");
option.appendChild(oText1);
oField.appendChild(option);
for(x in Menu){
var option=document.createElement("option");
option.setAttribute("value", x);
var oText1=document.createTextNode(x);
option.appendChild(oText1);
oField.appendChild(option);
}
document.getElementById("d").appendChild(oField);
var subsel=document.createElement("select");
subsel.setAttribute("id","Sub");
subsel.setAttribute("name","Sub");
document.getElementById("d").appendChild(subsel);
oField.setAttribute("onchange", " return aggiorna()");
}
else{
var option=document.createElement("option");
var oText1=document.createTextNode("scegli:");
option.setAttribute("disabled", "disabled");
option.setAttribute("selected", "selected");
option.setAttribute("value", "");
option.appendChild(oText1);
oField.appendChild(option);
for(x in Menu){
var option=document.createElement("option");
option.setAttribute("value", x);
var oText1=document.createTextNode(x);
option.appendChild(oText1);
oField.appendChild(option);
}
document.getElementById("d").appendChild(oField);
var subsel=document.createElement("select");
subsel.setAttribute("id","Sub");
subsel.setAttribute("name","Sub");
document.getElementById("d").appendChild(subsel);
oField.onchange= aggiorna();
}questa funzione al click su un pulsante tipo button dovrebbe fare comparire due select la prima select e quella aggiorna la seconda tramite la funzione aggiorna che posto di seguito
function aggiorna(){
var sel=document.getElementById("sel");
var subsel=document.getElementById("Sub");
//Azzero il contenuto della seconda select
for (var i = subsel.length - 1; i >= 0; i--)
subsel.remove(i);
var cat=sel.options[sel.selectedIndex].value;
for(var i=1 ; i<Menu[cat].length ; i++ ){
var opt1=document.createElement("OPTION");
opt1.setAttribute("value" , Menu[cat][i]);
var oText1=document.createTextNode(Menu[cat][i]);
opt1.appendChild(oText1);
document.getElementById("Sub").appendChild(opt1);
}
return true;}
Su mozilla funziona correttamente mentre su IE no in quanto non aggiorna la seconda select e da un errore sul ciclo for dove viene resettata la select precedente.
Qualcuno può aitarmi grazie in anticipo.

Rispondi quotando
