|
-
Apr 30th, 2001, 06:46 AM
#1
Thread Starter
Frenzied Member
Setting the focus on a DHTML page.
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.
-
Apr 30th, 2001, 11:16 AM
#2
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.
-
May 1st, 2001, 02:27 AM
#3
Thread Starter
Frenzied Member
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 ?
-
May 1st, 2001, 10:32 AM
#4
Frenzied Member
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.
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
-
May 1st, 2001, 10:47 AM
#5
Thread Starter
Frenzied Member
!
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 !!!!
-
May 1st, 2001, 11:07 AM
#6
Frenzied Member
Ok... your doing something wrong then.. cuz this works every time:
Code:
<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>
Remember that javascript is case sensitive so you have to type the names there exactly the same as in your tags
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|