Can anyone please tell me why this jsFiddle doesn't work?
The idea is simple is just suppose to input the selected text into the textbox..
HTML:
<input type="text" id="teste" maxlength="50">
<select>
<option onClick="nelson">nelson</option>
</select>
JavaScript:
function nelson(){
document.getElementById('teste').value =+ "nelson";
}
Thanks in advance
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>
was changed for three reasons:
onclick
is preferred to onClick
for consistency nelson
needed to be changed to nelson()
to actually call the function. select
html element it is better to use the
onchange
event on the root.document.getElementById('teste').value =+ "nelson";
+=
or =
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With