PDA

View Full Version : [Javascript+DOM]


DarkSun84
21-01-2008, 08:47
Ciao, volevo sapere perchè non funziona l'attributo onchange sulla select che viene creata tramite DOM, ossia quando apro la pagina mi apre subito l'alert mentre me lo dovrebbe aprire nel momento in cui cambio un'opzione nella select.


var address= document.createElement('select');
address.setAttribute("id",'addressHttp');
address.setAttribute("name",'addressHttp'+numberRow);

address.onchange= alert("change!");

theOption= document.createElement("OPTION");
theText= document.createTextNode("www.esa.it");
theOption.setAttribute("value","http://www.esa.int/esaCP/Italy.html");
theOption.appendChild(theText);
address.appendChild(theOption);
//altre opzioni...
document.getElementById("formID").appendChild(address);

isAlreadyInUse
21-01-2008, 08:52
Prova a metterlo alla fine
document.getElementById("formID").appendChild(address);
address.onchange= alert("change!");

DarkSun84
21-01-2008, 09:09
fatto ma mi da lo stesso problema. :(

isAlreadyInUse
21-01-2008, 09:13
Tiè
address.onchange=function(){
alert("change!");
}

DarkSun84
21-01-2008, 09:18
GRAZIE!! ora funziona alla grande! :) ma perchè tocca utilizzare questo costrutto? grazie ancora anche per la rapidità della risposta!