PDA

View Full Version : focus field



NRastogi
03-28-2003, 09: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.

Regards,
Nrastogi

JohnKrutsch
03-28-2003, 10:06 PM
You could set it up to constantly put the focus back on the box:

window.onload=function(){
setInterval("document.formName.SearchBoxName.focus()",1000);
}

beetle
03-28-2003, 10:08 PM
Why not something like this?

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

JohnKrutsch
03-28-2003, 10: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.

cheesebagpipe
03-28-2003, 10: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();

</script>

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

NRastogi
03-28-2003, 10:45 PM
I will try these options and post back any questions might popped up !

JohnKrutsch
03-28-2003, 10: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.