onchange() event for combobox in FireFox 11

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
Post Reply
miamy
Posts: 3
Joined: December 13th, 2014, 8:59 am

onchange() event for combobox in FireFox 11

Post by miamy »

Hi all!
I have very simple javascript code:

Code: Select all

<script  language="JavaScript">
function f()
{
 year_navigator.action="http://******/?q=node/" + year_navigator.year.value;
 year_navigator.submit();
}
</script>
<form  method="post" name="year_navigator">
Select year:
<select name="year"  width="200" onchange="f()">
       <option value="49" >2010 </option><br />
       <option selected value="50" >2009 </option><br />
       <option value="51" >2008 </option><br />
     </select>
</form>

But, it seems, this function doesn't work in FireFox 11 - when user changes the year, nothing more happens :( .
Yes, I know that FireFox 11 is out-to-date, but, maybe, community can advise me any workaround for this issue?
P.S. I am a newbie in web-development, so sorry if this question looks like too stupid :) .
User avatar
patrickjdempsey
Posts: 23686
Joined: October 23rd, 2008, 11:43 am
Location: Asheville NC
Contact:

Re: onchange() event for combobox in FireFox 11

Post by patrickjdempsey »

Supposedly it should work:
https://developer.mozilla.org/en-US/doc ... e/onchange

Firefox 11 might not like the way you are declaring your inline JavaScript... try:
<script type="text/javascript">
Tip of the day: If it has "toolbar" in the name, it's crap.
What my avatar is about: https://addons.mozilla.org/en-US/seamonkey/addon/sea-fox/
miamy
Posts: 3
Joined: December 13th, 2014, 8:59 am

Re: onchange() event for combobox in FireFox 11

Post by miamy »

patrickjdempsey, sorry for long delay with the answer.
Unfortunately

Code: Select all

<script type="text/javascript">
doesn't work too. Maybe, exists any other script declarations?
Thank you.
User avatar
patrickjdempsey
Posts: 23686
Joined: October 23rd, 2008, 11:43 am
Location: Asheville NC
Contact:

Re: onchange() event for combobox in FireFox 11

Post by patrickjdempsey »

It's certainly possible that there was just a bug with that feature which is now fixed.
Tip of the day: If it has "toolbar" in the name, it's crap.
What my avatar is about: https://addons.mozilla.org/en-US/seamonkey/addon/sea-fox/
User avatar
trolly
Moderator
Posts: 39851
Joined: August 22nd, 2005, 7:25 am

Re: onchange() event for combobox in FireFox 11

Post by trolly »

Giving an element a name will not create a variable of the same name.
The recommended way is to give it an id and access it using "document.getElementById()".
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
Dom1953
Posts: 52
Joined: July 24th, 2014, 6:02 am
Location: Australia

Re: onchange() event for combobox in FireFox 11

Post by Dom1953 »

Historically Netscape provided access to named forms javascript using similarly named properties of the document element and also within the document.forms collection, allowing access to (your) form using any of:

Code: Select all

document.year_navigator   // or
document.forms["year_navigator"] // or
document.forms.year_navigator
Microsoft then added to these options by reflecting the form object as a property of the window, hence allowing both

Code: Select all

window.year_navigator   // or simply
year_navigator
as means of accessing the form from within script. What was news to me is that Firefox has obviously added support for the IE access method since Firefox 11, so thank you for the question.

However I agree with Trolly that probably the most reliable and robust way of accessing the form in a cross browser environment is to add an id attribute (which can be the same as the name) to the form element and use the document.getElementById method to access it. The reasoning is simple - no browser can possibly afford to get getElementById wrong :-)
miamy
Posts: 3
Joined: December 13th, 2014, 8:59 am

Re: onchange() event for combobox in FireFox 11

Post by miamy »

trolly, yes, it's work fine! Thank you!

Merry Christmas and Happy New Year to all! :)
User avatar
trolly
Moderator
Posts: 39851
Joined: August 22nd, 2005, 7:25 am

Re: onchange() event for combobox in FireFox 11

Post by trolly »

You're welcome.

And thanks to Dom1953 for the explanation why it works on IE.
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
Post Reply