function cittaBox() { var selezione = Document.getElementById("selector"); var selezioneTxt = selezione.options[selezione.selectedIndex].text; Document.getElementById("txtBox").value=selezioneTxt;} <SELECT NAME="citta" id="selector" onchange="cittaBox()"> <OPTION value="Roma"> Roma </OPTION> <OPTION value="Milano"> Milano </OPTION> <OPTION value="Torino"> Torino </OPTION> <OPTION value="Napoli"> Napoli </OPTION> <OPTION value="Bari"> Bari </OPTION> <OPTION value="Taranto"> Taranto </OPTION> <OPTION value="Lecce"> Lecce </OPTION> </SELECT> </P> <P align= "center" id="selezione0"> <INPUT type="text" name="citta" size="40" id="txtBox"> </P>¿Alguna idea de por qué no funciona?
javascript distingue entre mayúsculas y minúsculas Usar documento en lugar de Documento aparte de eso, no hay problema con su código
function cittaBox() { var selezione = document.getElementById("selector"); var selezioneTxt = selezione.options[selezione.selectedIndex].text; document.getElementById("txtBox").value=selezioneTxt; }espero te respondan..
reemplace Document.getElementById por document.getElementById
Tu código se ve bien. Pero solo tienes un error. Cambiar documento to documento`. Minúsculas. Entonces funciona.
function cittaBox() { console.log(1) var selezione = document.getElementById("selector"); var selezioneTxt = selezione.options[selezione.selectedIndex].text; document.getElementById("txtBox").value=selezioneTxt; } <SELECT NAME="citta" id="selector" onchange="cittaBox()"> <OPTION value="Roma"> Roma </OPTION> <OPTION value="Milano"> Milano </OPTION> <OPTION value="Torino"> Torino </OPTION> <OPTION value="Napoli"> Napoli </OPTION> <OPTION value="Bari"> Bari </OPTION> <OPTION value="Taranto"> Taranto </OPTION> <OPTION value="Lecce"> Lecce </OPTION> </SELECT> </P> <P align= "center" id="selezione0"> <INPUT type="text" name="citta" size="40" id="txtBox"> </P>