Setting focus on specific SELECT option

Hi, my problem seems simple enough, but I can’t seem to find any solution to it.

I have a SELECT element in a form like this:

<td>
<select name="q_type" onChange="writeTxtBox(this.value);">
<option value="0">(select an option)</option>
<option value="SELECT">SELECT</option>
<option value="DELETE">DELETE</option>
<option value="INSERT">INSERT</option>
<option value="ORDER BY">ORDER BY</option>
</select>
</td>

When a user selects a value, the writeTxtBox() function is called:

function writeTxtBox(strVal) {

var queryTxt = new String();

 if (strVal != "0") {
	
	queryTxt = strVal + " ";
	
	document.myForm.txtBox.value += queryTxt;

 } // if

} // writeTextArea()

and the selected option will be added to the text input box.

What I want to do is, as soon as the user has clicked on an option and the value is written to the text box, the focus is then set back to the first option in the SELECT element, i.e. the one which says (select an option).

But so far I’ve only been able to set the focus on the SELECT element rather than on a specific option.

Does anyone have any ideas on how I can accomplish this?

Thanks!

rishi

Hi,

You can use the selected attribute to return the focus to a specific option.

function writeTxtBox(strVal) {

var queryTxt = new String();

 if (strVal != "0") {
	
	queryTxt = strVal + " ";
	
	document.myForm.txtBox.value += queryTxt;
        document.myForm.selectList.options[0].selected = true;

 } // if

} // writeTextArea()

Yours, Erik.

Whoa! That was fast! Thanks lilleman! You’ve just made a newbie very very happy! :smiley: