Focus

D

DeWayne

Can someone tell me how I could set the focus on a form
to a text box after the user runs the query at the top of
a form? I have a form I built that some of the text
boxes are set to the information being returned by the
query and I would like to place the cursor in a text
boxes half way down the form.


Any Help Would Be a Help

DeWayne
 
L

Lisa Wollin \(Microsoft\)

Hi, DeWayne,

First you need to give your form a name using the name attribute of the FORM
element. The following code gives the form the name "ContactForm".

<form name="ContactForm" ... >

Then you need to give your form controls names. The following code shows an
input textbox with the control name of "Name".

<input type="text" name="Name" class="input" />

Then in script you create a variable that references the form name and the
control name. The following accesses the "Name" control in the
"ContactForm" form.

var name = document.ContactForm.Name;

//Verifies that the name field is not empty.
if (name.value == "") {
alert("Please enter your name.");
name.focus();
return false;
}

The above code indicates that if the value of the name field is empty, to
display an alert message and put the input focus (focus method) in the name
control.

Hope this helps. There are many resources online that provide more detailed
instructions and examples on how to do this, and there are two articles on
MSDN about working with HTML forms at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncodecorn/html/corner111799.asp.

Lisa Wollin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top