How do I set input focus in an HTML menu?

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
Speednet
Super Advanced
Super Advanced
Posts: 33
Joined: Thu Nov 25, 2004 4:29 am

How do I set input focus in an HTML menu?

Post by Speednet »

I have a menu with type=html, and that menu has one input space. When the menu opens, I would like to set the input focus to that input space, so that the user already has the cursor blinking in it without having to click it.

I cannot find an "openfunction" property that would fire when the menu first opens (like the "load" attribute on the <body> tag). If there were such a property, I presumably could set that property to "document.form.textelement.focus()".

Anyone have a clue how to do this?

Thanks!
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

You could do it with a timed function, something like this:


function setFocus()
{
setTimeout("document.forms.search.q.focus()",100);
}

Assuming a form object named "search" and a text box called "q"


Called from the parent menu item with an onfunction embedded inside the aI string, like this:

aI("url=/search.php;text=Search;showmenu=mm search;onfunction=setFocus()");

Hope this helps
Andy
Speednet
Super Advanced
Super Advanced
Posts: 33
Joined: Thu Nov 25, 2004 4:29 am

Post by Speednet »

Interesting concept, thanks. It's actually a popup menu, so there's no parent. But I guess I could call the Timeout function just before calling popup(), right?
Speednet
Super Advanced
Super Advanced
Posts: 33
Joined: Thu Nov 25, 2004 4:29 am

Post by Speednet »

I just tested it - works great with a popup. I put the following code in the onClick event:

onClick="setTimeout('document.forms.frm.q.focus()',100);popup('menuname');"

Thanks again!
User avatar
rudy
Mega User
Mega User
Posts: 161
Joined: Thu Jan 15, 2004 11:39 pm
Location: Scottsdale, Arizona
Contact:

Post by rudy »

I'm interested in doing somethiing like that - mind sharing a URL so we can see it in action :?:
Speednet wrote:I just tested it - works great with a popup. I put the following code in the onClick event:

onClick="setTimeout('document.forms.frm.q.focus()',100);popup('menuname');"

Thanks again!
Rudy
Post Reply