MozillaZine

Javascript focus() and submit() problem!

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

Post Posted May 26th, 2014, 4:04 am

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

DanRaisch
Moderator

User avatar
 
Posts: 121099
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted May 26th, 2014, 4:32 am

Moving to Web Development.

CharlesEF
 
Posts: 148
Joined: November 21st, 2003, 4:56 am
Location: Edinburg, Texas

Post Posted May 26th, 2014, 6:41 am

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?

jscher2000

User avatar
 
Posts: 10432
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA

Post Posted May 26th, 2014, 3:06 pm

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

Post Posted May 26th, 2014, 4:37 pm

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

Post Posted May 27th, 2014, 5:08 am

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.

jscher2000

User avatar
 
Posts: 10432
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA

Post Posted May 28th, 2014, 6:05 pm

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

Post Posted May 29th, 2014, 3:20 pm

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

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 6 guests