HTML:
<input type="text" id="teste" maxlength="50" /> <select onchange="selectedItemChange(this)"> <option value="nelson">nelson</option> <option value="justin">justin</option> </select>
JS:
function selectedItemChange(sel) { document.getElementById('teste').value = sel.value; }
Explanation:
<option onClick="nelson">nelson</option>
document.getElementById('teste').value =+ "nelson";
- As many others have pointed out the proper operator is
+= or =
To set initial value do the following
DEMO: jsFiddle
HTML
<input type="text" id="teste" maxlength="50" /> <select id="select-people" onchange="selectedItemChange(this)"> <option value="nelson">nelson</option> <option value="justin">justin</option> </select>
JS
function selectedItemChange(sel) { document.getElementById('teste').value = sel.value; } window.onload=function(){ document.getElementById('teste').value = document.getElementById("select-people").value; }
onclickis not really javascript, I'd call it html (because it is a html-attribute), therefor not case sensative