Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   preventDefault() in Opera and Netscape (http://www.programmingforums.org/showthread.php?t=11495)

aaroncampbell Oct 4th, 2006 2:35 PM

preventDefault() in Opera and Netscape
 
I have built a Google Suggest type dropdown suggestion box. When it is open, the user can use the mouse OR keyboard to navigate it. If they use the keyboard, the up/down arrows should navigation options, and the enter should "select" and option...but NOT submit the form. Herein lies the problem. I'm using this code in an onkeydown event attached to the input field:
:

if (this.asc.style.visibility != 'hidden') {
    e.returnValue = false
    if (typeof e.preventDefault !== 'undefined') {
          e.preventDefault();
    }
}

For full code, see this paste. The lines in question are highlighted, and start at line 116: http://paste-bin.com/779

The code works in IE and Firefox, but NOT in Netscape, Opera, K-Meleon, etc. Instead in those browsers it "selects" the option (this.selectOption();) AND submits the form.

Also, if you are part of Experst-Exchange, feel free to get some points

aaroncampbell Oct 4th, 2006 2:40 PM

1 Attachment(s)
I realized that a paste-bin would be useless for future people finding this post. I'm attaching the code. In the attached version, the problem area starts on line 109


All times are GMT -5. The time now is 1:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC