MozillaZine

onchange() event for combobox in FireFox 11

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

Post Posted December 13th, 2014, 9:13 am

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 :) .

patrickjdempsey

User avatar
 
Posts: 23734
Joined: October 23rd, 2008, 11:43 am
Location: Asheville NC

Post Posted December 13th, 2014, 3:51 pm

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

Post Posted December 21st, 2014, 3:06 pm

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.

patrickjdempsey

User avatar
 
Posts: 23734
Joined: October 23rd, 2008, 11:43 am
Location: Asheville NC

Post Posted December 21st, 2014, 5:34 pm

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/

trolly
Moderator

User avatar
 
Posts: 39908
Joined: August 22nd, 2005, 7:25 am

Post Posted December 21st, 2014, 6:44 pm

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

Post Posted December 22nd, 2014, 5:34 pm

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

Post Posted December 24th, 2014, 5:28 am

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

Merry Christmas and Happy New Year to all! :)

trolly
Moderator

User avatar
 
Posts: 39908
Joined: August 22nd, 2005, 7:25 am

Post Posted December 24th, 2014, 6:17 am

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.

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 1 guest