View Full Version : focus field

Mar 28th, 2003, 10:05 PM
Hi Guys,

I have created two frames, one has a search box and a go button. In the other frame the search results get displayed with additional buttons to order products etc.

Problem: I want to keep the focus in the search box of the top frame all the time, even they clicked on "go" button, the focus should go back to the search field.

The top frame does not get refreshed, only the other "main" frame where it displays search results, gets refreshed.

Is there a way to get this working? Please suggest.

Thanks a lot in advance.


Mar 28th, 2003, 11:06 PM
You could set it up to constantly put the focus back on the box:


Mar 28th, 2003, 11:08 PM
Why not something like this?

<form ... >
<input type="text" name="search" />
<input type="submit" value="Go" onmouseup="this.form.search.focus()" />

Mar 28th, 2003, 11:19 PM
Because as soon as the other frame loads it should get focus. Any other user action will also cause the filed to lose focus. Using set interval will ensure that no matter what happens the field should get focus every second.

Then again I could be wrong, this is just my rationale.

Mar 28th, 2003, 11:29 PM
Unfortunately, Frameset.onload is only called the first time the frameset is loaded (and not on subsequent frame page switching); the best way to do this is probably to call some JS onload of the main frame which sets the focus explicitly:

<script type="text/javascript">

onload = top.search.document.myform.searchbox.focus();


Sure you want to do this? Consider it from the user's perspective....

Mar 28th, 2003, 11:45 PM
I will try these options and post back any questions might popped up !

Mar 28th, 2003, 11:49 PM
Do you have control over the "search result pages" are are they comming from somehwere else? If you do the cheesebagpipe suggestion is a good way to go, I just assumed that you did not have control over them. I also assumed you have control over the page that has the search box on it, that is where you would insert the code I suggested, not on the frameset page.

cheesebagpipe also make as a good point about usability. If you tell us more about why you want to do this we may be able to help you come up with better solutions.