Javascript focus() and submit() problem!

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
Post Reply
CharlesEF
Posts: 148
Joined: November 21st, 2003, 4:56 am
Location: Edinburg, Texas

Javascript focus() and submit() problem!

Post by CharlesEF »

Hi All,

I have come across 2 problems using FF 29.0.1 that I can't figure out and I'm looking for some help:

1.) When my page loads I have js code 'document.getElementById('dbtype').focus();' that should set focus to the first element. The element is a <select> tag and according to the tab order it does have focus (I can tab and I do go to the next element). However, there is no indication that the element has focus, like dotted lines, or anything. IE8 does show focus by having dotted lines inside the element. Why does FF not show this also?

2.) I use js code 'document.getElementById("cefiform").submit();' to submit the form but Firebug tells me that submit() is not a function. If I remove the () character then I do not get any errors but the form does not submit. Why?


Thank you for any and all help,

Charles
User avatar
DanRaisch
Moderator
Posts: 127246
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: Javascript focus() and submit() problem!

Post by DanRaisch »

Moving to Web Development.
CharlesEF
Posts: 148
Joined: November 21st, 2003, 4:56 am
Location: Edinburg, Texas

Re: Javascript focus() and submit() problem!

Post by CharlesEF »

I figured out the problem with submit(). I have an actual submit button on the form. When this button is present the javascript submit will not work. When the button is removed the javascript submit works. I guess you can't have 2 submits for the same form? If so then I will have to re-think my design. Can anyone confirm?
User avatar
jscher2000
Posts: 11772
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA
Contact:

Re: Javascript focus() and submit() problem!

Post by jscher2000 »

You should be able to use a submit button (input type="submit"). However, there is an old issue with using name="submit" on a form control, so you should change that if you have it.
CharlesEF
Posts: 148
Joined: November 21st, 2003, 4:56 am
Location: Edinburg, Texas

Re: Javascript focus() and submit() problem!

Post by CharlesEF »

Thank you, I will try it. Any idea about the focus() problem?
CharlesEF
Posts: 148
Joined: November 21st, 2003, 4:56 am
Location: Edinburg, Texas

Re: Javascript focus() and submit() problem!

Post by CharlesEF »

Ok, I renamed the 'id' and 'name' attribute (I use both) and the javascript submit did work correctly. I'm still trying to figure out why there is no indication that a select has focus when using javascript to set the focus.

The strange thing is that if I tab forward and then tab backward the select does show a dotted outline inside the select (like IE8). I think it should do that from the start, when it gets focus when the page loads.
User avatar
jscher2000
Posts: 11772
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA
Contact:

Re: Javascript focus() and submit() problem!

Post by jscher2000 »

There were some changes with <select> recently, for example, the behavior of the Enter key was changed. See: Firefox 29 update does not recognize event "keypress" when pressing (intro) (keycode 13) over <select> element on form | Firefox Support Forum | Mozilla Support. This could be completely unrelated, or it might be a side effect. But it does seem like a regression from the desired behavior.
CharlesEF
Posts: 148
Joined: November 21st, 2003, 4:56 am
Location: Edinburg, Texas

Re: Javascript focus() and submit() problem!

Post by CharlesEF »

Well, I'm not sure the problem is related but I could be wrong. My <select> is the first element on the page so I should not need javascript to set focus. Even when I comment out the focus() section FF still does not show any indication that the <select> has focus, unless I happen to tab back and forth to it.

I guess I'll have to wait for the next update to see if it gets fixed.


Thank you for your help,

Charles
Post Reply