Set focus on Dropdown list?

liunx

Guest
Hi all. This is my first time in here! I have a question. When a page loads up I want the focus to initially be set on a dropdown list. Right now it is set on a text box. Here is what the (javascript/html) code looks like:<br />
function SetFocus()<br />
{for (i=0; i<NumElements; i++)<br />
if (document.LANSA.elements.type == "textarea" ||<br />
document.LANSA.elements.type == "text" ||<br />
document.LANSA.elements.type == "checkbox" ||<br />
document.LANSA.elements.type == "radio")<br />
{document.LANSA.elements.focus();<br />
break;}<br />
}<br />
<br />
So how would I have a dropdown list (selection list) be part of those options, (since selection lists do not have a "type" property). Clear as mud? Thanks in advance!<!--content-->This is just a test reply to myself, to make sure I did this right!<!--content-->I'm assuming that you know when the page loads which select box you want to focus on? If so, then you can set the focus as follows:<br />
<br />
<html><br />
<head><br />
<script language = "JavaScript"><br />
function setFocus(){<br />
document.form1.select1.focus();<br />
}<br />
</script><br />
</head><br />
<body onFocus = setFocus();><br />
<form name = "form1"><br />
Text Box<br />
<input type = "text" name = "text1"><br />
<br><br />
Select Box <br />
<select name = "select1"><br />
<option value = "1">Value 1</option><br />
<option value = "2">Value 2</option><br />
<option value = "3">Value 3</option><br />
</select><br />
</body><br />
</form><br />
</html><!--content-->It may be better to change this line:<br />
<br />
<body onFocus = setFocus();><br />
<br />
to this:<br />
<br />
<body onload="setFocus();"><br />
<br />
because otherwise every time they switch to a differend window and come back to yours again it will set the focus back to the dropdown menu. That's fine if that's the effect your looking for but you did say:When a page loads up I want the focus to initially be set...so I thought I'd just mention it.<!--content-->
 
Back
Top