Placing cursor into search field

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
shacker
Advanced
Advanced
Posts: 19
Joined: Thu Dec 18, 2003 4:41 am
Location: Berkeley, CA
Contact:

Placing cursor into search field

Post by shacker »

I've got a drop-down Search field in a Milonic menu, which is working nicely.

http://dev.journalism.berkeley.edu/alumni/

I'm trying to configure it so that the cursor is placed automatically in the search field when the Search item is selected. I know how to do this in the BODY tag when the field is already part of the page:

onLoad="self.focus();document.contacts.SearchTerm.focus()"

but how can I do it when it's part of a menu item? Is it even possible? I notice that Milonic don't even do this with their own Search menu item, so maybe it's not...

Thanks,
scot
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

Hi,

It's been done. From Andy,

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

Code: Select all

<script> 
function setFocus() 
{ 
setTimeout("document.forms.search.q.focus()",100); 
} 
</script>
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:

Code: Select all

aI("url=/search.php;text=Search;showmenu=mm search;onfunction=setFocus()")
One thing to keep in mind, check your overfilter if you have it set. If anything, for example let's say you are using fade, if the duration is set to more than what you set as the time in the setTimeout, you need to increase the set time out so that the menu is fully loaded before the setTimeout fires.

Ruth
shacker
Advanced
Advanced
Posts: 19
Joined: Thu Dec 18, 2003 4:41 am
Location: Berkeley, CA
Contact:

Post by shacker »

Bingo, that works! Many thanks Ruth.
Post Reply