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

Posted on 2009-02-20
Last Modified: 2013-12-08
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 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:  
function SubmitOnEnter(myfield, e)  
var keycode;  
if (window.event)  
keycode = window.event.keyCode;  
else if (e)  
keycode = e.which;  
return true;  
if (keycode == 13)  
return false;  
return true;  

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

Question by:MHenry
    LVL 15

    Accepted Solution

    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
    LVL 7

    Author Comment

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

    LVL 15

    Expert Comment

    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)"

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Read about why website design really matters in today's demanding market.
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now