[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 918
  • Last Modified:

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
0
MHenry
Asked:
MHenry
  • 2
1 Solution
 
aibusinesssolutionsCommented:
Have you thought about using another flash js file instead of the AC_RunActiveContent.js?

There's a nice one that I always use called SWFObject located here, it doesn't intercept window.events

http://code.google.com/p/swfobject/
0
 
MHenryAuthor Commented:
That might work on the Flash pages anyway. I'll give it a shot.

Thanks!
MH
0
 
aibusinesssolutionsCommented:
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)"
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now