Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to position the cursor(focus)

Status
Not open for further replies.

discusmania

IS-IT--Management
Oct 24, 2000
158
AP
Hi Guys...
Let say i have a long form that took me more than one page to display. when i submit the form i want the same form to be displayed but with the cursor(focus) at a combobox at the bottom of the form rather than the top of the form. Can i do that, if so how?

Thanks for your help

Ron
 
Easiest way I can think of requires a snippet of script.

Here's an example (I assume you mean "dropdown" rather than "combo box" since there isn't an HTML combo box - only dropdowns and listboxes - 's far as I know anyway).
Code:
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE>Set Focus Example</TITLE>
</HEAD>
<BODY onload=&quot;select4.focus()&quot;>
<table border=1>
	<tr><td>One</td><td><INPUT id=text1 name=text1></td></tr>
	<tr><td>Two</td><td><INPUT id=text2 name=text2></td></tr>
	<tr><td>Three</td><td><INPUT id=text3 name=text3></td></tr>
	<tr><td>Four</td>
		<td><SELECT id=select4 name=select4 size=1
				 style=&quot;WIDTH: 155px&quot;>
			<OPTION selected value=1>Mercury</OPTION>
			<OPTION value=2>Venus</OPTION>
			<OPTION value=3>Earth</OPTION>
			<OPTION value=4>Mars</OPTION>
			<OPTION value=5>Jupiter</OPTION>
			<OPTION value=6>Saturn</OPTION>
			</SELECT>
		</td></tr>
</table>
</BODY>
</HTML>

Possible caveat: Microsoft suggests that as of IE 5 this only works (the object.focus() method, that is) for elements which have tabindex set. But it seems to work fine without it, at least on IE6.
 
Hey Ron,
This is a Client side process and I'm afraid and you, my man, are going to use Javascript!

Get your page to run a simple script from the 'onload' event like this (try it, it really works!):

<html>
<head>
<title>Dave's Magical Focus Form</title>
<script language=&quot;JavaScript&quot;>
<!--
function SetFocusOnItem(pickme) {
document.all.item(pickme).focus();
}
// -->
</script>
</head>

<body onLoad=&quot;SetFocusOnItem('dave')&quot;>
<form name=&quot;Funky&quot; >
<p>
<input type=&quot;text&quot; name=&quot;Dave&quot;>
This field is called dave</p>
<p>
<input type=&quot;text&quot; name=&quot;frank&quot;>
This field is frank</p>
</form>
</body>
</html>

I hope this solves your problem!

Regards
Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top