473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

onChange failing in Firefox, ok in IE

I have a fairly basic Javascript that is taking a selected value in a select and making a div on the page visible when selected, hiding it when unselected. It works great in IE, but Firefox is not displaying anything.

Expand|Select|Wrap|Line Numbers
  1. function initSelect()
  2. {
  3.     var theSelect = document.getElementById("Affiliation");
  4.  
  5.     theSelect.changed = false;
  6.     theSelect.onfocus = selectFocussed;
  7.     theSelect.onchange = selectChanged;
  8.     theSelect.onkeydown = selectKeyed;
  9.     theSelect.onclick = selectClicked;
  10.  
  11.     return true;
  12. }
  13.  
  14.  
  15.  
  16.  
  17. function selectChanged(theElement)
  18. {
  19.     var theSelect;
  20.  
  21.     if (theElement && theElement.value)
  22.     {
  23.         theSelect = theElement;
  24.     }
  25.     else
  26.     {
  27.         theSelect = this;
  28.     }
  29.  
  30.     if (!theSelect.changed)
  31.     {
  32.         return false;
  33.         test.style.visibility = 'hidden';
  34.     }
  35.  
  36.     if (theSelect.selectedIndex == 13)
  37.     {
  38.         test.style.visibility = 'visible';
  39.     }
  40.     else
  41.     {
  42.         test.style.visibility = 'hidden';
  43.     }
  44.  
  45.     return true;
  46. }
  47.  
  48.  
  49.  
  50.  
  51. function selectClicked()
  52. {
  53.     this.changed = true;
  54. }
  55.  
  56.  
  57.  
  58.  
  59. function selectFocussed()
  60. {
  61.     this.initValue = this.value;
  62.  
  63.     return true;
  64. }
  65.  
  66.  
  67.  
  68.  
  69. function selectKeyed(e)
  70. {
  71.     var theEvent;
  72.     var keyCodeTab = "9";
  73.     var keyCodeEnter = "13";
  74.     var keyCodeEsc = "27";
  75.  
  76.     if (e)
  77.     {
  78.         theEvent = e;
  79.     }
  80.     else
  81.     {
  82.         theEvent = event;
  83.     }
  84.  
  85.     if ((theEvent.keyCode == keyCodeEnter || theEvent.keyCode == keyCodeTab) && this.value != this.initValue)
  86.     {
  87.         this.changed = true;
  88.         selectChanged(this);
  89.     }
  90.     else if (theEvent.keyCode == keyCodeEsc)
  91.     {
  92.         this.value = this.initValue;
  93.     }
  94.     else
  95.     {
  96.         this.changed = false;
  97.     }
  98.  
  99.     return true;
  100. }
  101.  
Expand|Select|Wrap|Line Numbers
  1. <select name="thename" id="selector">
  2. <option selected>0</option>
  3. <option>1</option>
  4. <option>2</option>
  5. .
  6. .
  7. .
  8. <option>13</option>
  9. </select>
  10.  
  11. <div id="test" style="visibility:hidden;">Visible in IE, not in Firefox</div>
  12.  
Any suggestions? Thanks!
Nov 29 '06 #1
2 2719
AricC
1,892 Expert 1GB
What function are you calling on your onchange event?
Nov 29 '06 #2
I ended up finding the problem w/ Firefox's debugger. I just needed to declare the hidden DIV as a variable using getElementbyID. Once I did that, Firefox smartened up and found the DIV and, wouldn't ya know it, it worked!
Nov 30 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Asit | last post by:
In JavaScripts checks for an onChange event against the value of the textbox at the time of the last onChange event. Since an onChange Event never fired after you changed the text first time ,...
4
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on...
3
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having...
4
by: David McNerney | last post by:
Would anyone be able to tell me why I get an error in FireFox 1.5.0.1 for MacOSX when I type some text and hit Enter in the following form: <html> <body> <form action="http://example.com"...
10
by: david.bercot | last post by:
Hi, I have a big problem with a simple event : onchange !!! If I write this page : <html> <body> <form id="vu"> <input id="var01" name="var01" size="5" onchange="return false;"/> </form>...
1
by: Stewart | last post by:
Dear All, I discovered last night that IE6 doesn't support the onchange event on the form object. I had written some script in Firefox, and tested in IE, and spent a long time trying to debug...
1
by: Jan Doggen | last post by:
Hello all, I have a SELECT like this (the 'alert()s are temporary): <FORM method="POST" action="/scripts/runisa.dll?OVB2.132964:PGSPLITVACAFMELDEN:1095144287.9159" id="hulpform"...
7
by: Tim Slattery | last post by:
I'm trying to handle the onChange event in an <input type="file"> element. In IE, there's no problem: the event fires when a file in the "open" box is doubleclicked, or the "Open" button in the box...
1
by: daokfella | last post by:
I need to raise the onchange event and Firefox is giving me some grief. I hear fireEvent is buggy with some events. Is that true? My code is simply this: targetTextbox.fireEvent("onChange"); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.