[Javascript] Re: <select> focussieren

Matt Barton javascript at mattbarton.org
Tue Feb 8 06:37:40 CST 2005


This is one way to do it:

To ensure that the correct option is selected when the page loads then 
the html should resemble this:

<select id="theSelect">
	<option value="a">This should not be selected</option>
	<option value="b" selected>This SHOULD be selected</option>
</select>

It is the "selected" part of the correct <option> tag that makes it 
appear selected.

To get the focus onto the select control, you've almost got it right. 
The javascript for the above example could be:

document.getElementById("theSelect").focus();

There's many similar ways to achieve the same thing though: this is just 
one.

HTH

Matt


Michael Borchers wrote:
> oh, sorry for that!
> 
> i would like to focus a <select><option ... > field when 
> loading a form, so I can browse the options with the mouse wheel f.e.,
> but without using a onLoad() in the <body> tag, is that possible?
> 
> document.formname.selectname.options.focus();
> 
> did not work
> neither
> 
> document.formname.selectname.options[document.formname.selectname.selectedIndex].value.focus();
> 
> 
>  
> 
>>> -----Ursprüngliche Nachricht-----
>>>Von: 	Michael Borchers  
>>>Gesendet:	Dienstag, 8. Februar 2005 13:23
>>>An:	Javascript (E-Mail)
>>>Betreff:	<select> focussieren
>>>
>>>undzwar direkt beim aufruf des formulares ohne <body> tag, 
>>
>>geht das?
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
> 



More information about the Javascript mailing list