Closed Bug 489375 Opened 15 years ago Closed 14 years ago

on firefox 3 evt.preventDefault() does not work when an ajax request is dispatched

Categories

(Firefox :: General, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED INCOMPLETE

People

(Reporter: csaviani, Unassigned)

Details

(Whiteboard: [CLOSEME 2010-11-01])

Attachments

(2 files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20

I hope to be in the right place to post this bug, if not I apologise and ask for the right place.

I have two HTML text boxes, on the firt one I have a keydown eventhandler.
The associated function retrives the keyCode from the event object to see if the tab key has been pressed, in which case the preventDefault function is called.
After this call a synchronous ajax request is dispatched and its responseText is sent to the text box which has the focus.
In Firefox 2 the text box with the focus is the same where the tab key has been pressed, in Firefox 3 is the next text box. 





Reproducible: Always

Steps to Reproduce:
1. Any Servlet that sends back a text response will be OK.
2. The JSP code:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
       <script>
            var currentElement;
            function sendAjaxRequest(params){
                var url = "/ProvaUTF8/AjaxServlet"
                var ajaxRequest = new XMLHttpRequest();
                ajaxRequest.open("POST", url, false);
                ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                ajaxRequest.send(params);
                return ajaxRequest.responseText;
            }
            function doKeyDown(evt){
                if(evt.keyCode != 9) return;
                evt.preventDefault();
                var value = currentElement.value;
                var params = "value=" + encodeURIComponent(value);
                var result = sendAjaxRequest(params);
                currentElement.value = result;
            }
        </script>
    </head>
    <body>
        <input id="txt1" type="text" onfocus="currentElement=this;" onkeydown="doKeyDown(event)"/>
        <input id="txt2" type="text" onfocus="currentElement=this;"/>
    </body>
</html>




I found a work around setting the attribute tabinde="-1" on the second text box, but this means that I need to replicate this attribute on every text box of the form and write the necessary code to manage the navigation via keyboard.
This is a mass search for bugs which are in the Firefox General component, are
UNCO, have not been changed for 500 days and have an unspecified version. 

Reporter, can you please update to Firefox 3.6.10 or later, create a fresh profile, http://support.mozilla.com/en-US/kb/managing+profiles, and test again. If you still see the issue, please update this bug. If the issue is gone, please set the status to RESOLVED > WORKSFORME.
Whiteboard: [CLOSEME 2010-11-01]
No reply from reporter, INCOMPLETE. Please retest with Firefox 3.6.12 or later and a new profile (http://support.mozilla.com/kb/Managing+profiles). If you continue to see this issue with the newest firefox and a new profile, then please comment on this bug.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INCOMPLETE
Same problem using Firefox 8. My test case is about the same.
Attached file FF13 test case
I can also reproduce this issue on FF 13.0.1 on Windows 7.

To reproduce:
1) Focus the first text box
2) Type "abc"
3) Press tab to kick off the synchronous Ajax request

The focus changes to the second field, even through preventDefault was called.
Yeah, have the same problem here, Win7 + recent FF (UA: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0).

As far as my debugging goes, in case of firing synchronous request during keydown event (possibly keypress too as mentioned by others) an **extra keypress is fired**. So it's not really like you can't call `preventDefault` but it's more about extra keypress being fired in this case.

I've attached another simple demo "Proof for double keypress firing." for this issue: https://bugzilla.mozilla.org/attachment.cgi?id=8599425
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: