Closed Bug 7133 Opened 25 years ago Closed 25 years ago

onFocus event does not work if we try to give focus to element using JS method focus()

Categories

(Core :: DOM: UI Events & Focus Handling, defect, P3)

x86
Windows 95
defect

Tracking

()

VERIFIED FIXED

People

(Reporter: desale, Assigned: rods)

References

Details

(Whiteboard: [PDT+]I have a fix)

onFocus event does not work if we try to give focus to element using JavaScript method focus(). focus() method seems working fine since I can see blinking curson in element, and onFocus event also works fine if I try to give focus using mouse. This event just does not take place when I try to give focus using method focus(). Product: seamonkey [Apprunner/ Viewer] Build: 05-25-09. Steps to reproduce bug: 1] Please copy the code I'm providing. Save as HTML file and open this file in viewer as well as apprunner. 2] You'll see one Testing text box, which is supposed to get default focus from javascript method focus(). 3] You'll see one more text box called Result Text Box, which prints result of onFocus event. 4] Now try to click in Testing Text Box. Expected Results: As soon as page loads "Result Text Box" should show that "Testing Box Got Focus" since we are giving focus to testing text box through javascript. Actual Results: "Result Text Box" does not show anything. But we can see blinking cursor in testing text box. Conclusion: This means onFocus event does not work if we try to give focus using focus() method. CODE: <html> <head> <title>Test Page</title> </head> <SCRIPT LANGUAGE="JavaScript1.1"> function report(text) { var value=document.workform.result.value; var msg= value+ " " +text; document.workform.result.value=msg; } </SCRIPT> <body > <form name="workform"> Testing Text Box:<INPUT TYPE=text name="testing1" size=15 onFocus="report('Testing Box Got Focus');"> Result Text Box:<INPUT TYPE=text name="result" size=60><br><br> <SCRIPT LANGUAGE="JavaScript1.1"> document.workform.testing1.focus(); </SCRIPT> <input type="reset" value="Reset"> </form> </body> </html> END OF CODE.
QA Contact: 3847 → 4616
Changing QA contact to myself.
Whiteboard: [MAKINGTEST] compact@cam.org
Blocks: 12162
Assignee: joki → rods
Status: NEW → ASSIGNED
Whiteboard: [MAKINGTEST] compact@cam.org → I have a fix
A couple of things. First it is invalid to have script embedded in the HTML. Since the DOM isn't fully built it is invalid to execute script on it. If I put the .focus() in a onload handler it will now work. Waiting to check in.
Status: ASSIGNED → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
This will work for all form controls but the textfield and textarea. That is a separate bug. marking fixed as in a general case.
Status: RESOLVED → REOPENED
This needs to be reopened because I had to back out my change because it didn't work on Linux.
Resolution: FIXED → ---
Clearing Resolution.
Putting on [PDT]+ radar.
Whiteboard: I have a fix → [PDT+]I have a fix
Status: REOPENED → RESOLVED
Closed: 25 years ago25 years ago
Resolution: --- → FIXED
Fixed, checked in, tested.
Status: RESOLVED → VERIFIED
Working fine. Tested with 10-19-09 builds.
Component: Event Handling → User events and focus handling
You need to log in before you can comment on or make changes to this bug.