Andy6666uk
Programmer
I have this code which puts the selection from a list box into a textbox. But I have more than one textbox on the page and want the selection to go into whichever textbox has focus. Any help greatly appreciated.
function handleListChange(theList) {
var numSelected = theList.selectedIndex ;
if (numSelected != 0) {
textValue = document.form.textbox.value ;
textValue = textValue + theList.options[numSelected].value ;
document.form.textbox.value = textValue ;
theList.selectedIndex = 0 ;
document.form.textbox.focus() ;
}
}
<form name=form action="etc." method="post">
<input type="text" name="textbox">
<input type="text" name="textbox2">
<input type="text" name="textbox3">
<select name="e" size="1" onChange="handleListChange(this)">
<option value="0"> 0 </option>
<option value="1"> 1 </option>
<option value="2"> 2 </option>
</select>
</form>
thanks again.
function handleListChange(theList) {
var numSelected = theList.selectedIndex ;
if (numSelected != 0) {
textValue = document.form.textbox.value ;
textValue = textValue + theList.options[numSelected].value ;
document.form.textbox.value = textValue ;
theList.selectedIndex = 0 ;
document.form.textbox.focus() ;
}
}
<form name=form action="etc." method="post">
<input type="text" name="textbox">
<input type="text" name="textbox2">
<input type="text" name="textbox3">
<select name="e" size="1" onChange="handleListChange(this)">
<option value="0"> 0 </option>
<option value="1"> 1 </option>
<option value="2"> 2 </option>
</select>
</form>
thanks again.