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>
any idea on why it doesn't work?
javascript is a case sensitive Use document instead of Document other than that nothing problem with your code
function cittaBox() {
var selezione = document.getElementById("selector");
var selezioneTxt = selezione.options[selezione.selectedIndex].text;
document.getElementById("txtBox").value=selezioneTxt;
}
i hope you get answer..
replace Document.getElementById by document.getElementById
Your code looking good. But you have only one mistake. Change Documenttodocument`. Lowercase. Then it work.
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>