Link to home
Start Free TrialLog in
Avatar of MHenry
MHenry

asked on

javascript onfocus enter key priority - Google search, Flash Video, IIS6, asp.net and all browsers...

Is there a way to prioritize which event has priority when using the enter key? What I want is when the focus is on the search box the enter key works the search box...

I've recently enabled Google search on our site. That was quite a struggle since I'm using Master Pages, but I've got that working. The problem is, if there is a form or even a Flash Video on the page, the enter button doesn't work as expected. Even though the focus is on the search, hitting the enter button triggers the form on the page. Or, in the case of a Flash Video, causes the page to refresh and the video to start playing.

I figure it's because there are conflicts between the javascript (AC_RunActiveContent.js) used to automatically launch any Flash content on a page and a conflict between the asp.net submit_Click event.

Here's  the code I'm using to capture the enter key for the search box. It works fine on pages where there is no other submit_Click event or Flash content.

// Retrieved from: http://www.htmlcodetutorial.com/forms/index_famsupp_157.html 
function SubmitOnEnter(myfield, e)  
{  
var keycode;  
if (window.event)  
keycode = window.event.keyCode;  
else if (e)  
keycode = e.which;  
else  
return true;  
if (keycode == 13)  
{  
SearchSite();  
return false;  
}  
else  
return true;  
}  



Sorry for the complexity of the question but that's what's happening...

Best,
MH
ASKER CERTIFIED SOLUTION
Avatar of aibusinesssolutions
aibusinesssolutions
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MHenry
MHenry

ASKER

That might work on the Flash pages anyway. I'll give it a shot.

Thanks!
MH
Also, you didn't paste the code you have for your search box.  I'm sure you have it, but just incase, make sure you have OnClientClick="SubmitOnEnter(this, e)", or if it's a normal html input OnClick="SubmitOnEnter(this,e)"