This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes document.forms[0].elements.focus() is not working in IE 7.0+ and FF 3.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "document.forms[0].elements.focus() is not working in IE 7.0+ and FF 3.0" Watch "document.forms[0].elements.focus() is not working in IE 7.0+ and FF 3.0" New topic
Author

document.forms[0].elements.focus() is not working in IE 7.0+ and FF 3.0

Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 229
Hello Friends,

I am trying the following code since long time .As It prompts and runs fine in IE 6.0 but in all the upper versions it fails .As cursor moves to next textbox rather than the same .




I am using that code in my JSP as





Please help me I tried lots of things but failed !!!


God Gave Me Nothing I Wanted, He Gave Me Everything I Needed.
OCPJP6
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Do the id.focus() after the alert statement

You also probably want to use onblur

Eric
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Apart from this problem, using document.forms[x] instead of document.formname or document.getElementById(formid) is a bad practice and receipt for trouble.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

Indeed. Using names instead of ids for DOM navigation is a quaint and old-fashioned practice that should be avoided.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 229
Bauke Scholtz wrote:Apart from this problem, using document.forms[x] instead of document.formname or document.getElementById(formid) is a bad practice and receipt for trouble.


Thanks For Early Reply! But I tried lots of things but failed .As all the time cursor moves to next textbox.It is working fine with IE6.0 but for latest browser it prompts but on clicking OK button it moves to next textbox without further prompting.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Someone said something about onblur.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
onchange is not fired on every keystroke. It is fired when focus is removed from the element and the data has changed.

Eric
Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 229
Eric Pascarello wrote:onchange is not fired on every keystroke. It is fired when focus is removed from the element and the data has changed.

Eric


Thanks Eric !! But It is Still not running .
I am sending my javascript code which is in js file



I am calling this function as



It is not working in IE 7.0 and FF 3.0 !!




Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 229
Any One can solve this problem ??
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: document.forms[0].elements.focus() is not working in IE 7.0+ and FF 3.0
 
Similar Threads
Ajax, Struts, and a few pesky event based issues
Access Data from Database By Submitting The select Values
Toolbar with color pallette ,different font styles and font sizes
URGENT Help needed on JavaScript.
document.forms[0].submit(); throws Invalid Argument in IE