How do I set the focus on a particular textarea control when my page loads into the browser ?
At the moment when it loads nothing seems to have the focus, and I have to click into the box manually !
Any response much appreciated.
Thanx.
Printable View
How do I set the focus on a particular textarea control when my page loads into the browser ?
At the moment when it loads nothing seems to have the focus, and I have to click into the box manually !
Any response much appreciated.
Thanx.
One way of doing this:
In the window onload event place this:
Formname.Controlname.focus();
I am not sure if this is the right way but it works.
I gave it a go, but it fell over with an 'Object Required' error.
This was my code :
********************************************
Private Sub BaseWindow_onload()
DHTMLPage1.txtSCRDescription.focus
End Sub
********************************************
Any more ideas ?
Is that (DHTMLPage1) the NAME of your form? As in, the name attribute inthe FORM tag. If not, it's not finding the text control. Also make sure you use the name attribute (I use both name and id and set them to the same thing) in any form data tags.
You didn't post all the code so I couldn't tell whether this is the problem or not.. but it sure sounds like it.
Yes, DHTMLPage1 is the name of my form.
It appears under the 'name' and the 'id' already.
But thanks for responding. Any more ideas ?
The control I am trying to set the focus on is a textarea control.
The form has a 'RESET' button which clears all fields and sets the focus to this control. This works fine. I just can't get it to set the focus when the form is loaded !!!!
:mad:
Ok... your doing something wrong then.. cuz this works every time:
Remember that javascript is case sensitive so you have to type the names there exactly the same as in your tagsCode:<HTML>
<HEAD>
<SCRIPT language=javascript>
function window_onload()
{
MyForm.MyText.focus();
}
</SCRIPT>
</HEAD>
<BODY onload="window_onload()" link="red">
<form name="MyForm" id="MyForm">
<input name="MyText" id="MyText" type="textarea">
</FORM>
</BODY>
</HTML>