It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

dropdown box image swap: firefox vs. IE7...grrr

Re: dropdown box image swap: firefox vs. IE7...grrr

Postby rangana on Wed Apr 15, 2009 10:52 pm

First, you should note that you have conflicting events.

An element's event could only be used once, otherwise, the second call will override the first.

Let me point you on this error:
Code: Select all
<body id="company" onload="myPreload('white.jpg', '601.jpg', '602.jpg');">


You were calling "myPreload" function, on the onload event. This isn't erroneous in the first place, but it appears you're calling another function on the same event of "body" element. It's this part:
Code: Select all
window.onload=make_hover_list;


Since the "inline" onload event comes later than your anonymous function assignee, then the above noted code is replaced by your "myPreload()" call.

To fix that issue, you need to do it like this:
Code: Select all
window.onload=function () {
   make_hover_list;
   myPreload('white.jpg', '601.jpg', '602.jpg');
}


Going back to your issue, I suggest on using "switch" statement instead. This part:
Code: Select all
<select name="bottom-end" class="custom"  onchange="var bottom1=document.getElementById('bottom1'), bottom2 = document.getElementById('bottom2'), bottom3 = document.getElementById('bottom3'), bottom4 = document.getElementById('bottom4'); alert(this.value);
bottom1.style.display=this.value=='foil'?'none':''; bottom2.style.display=this.value=='foil'?'':'none'; ">
<option value="type" selected="selected">Bottom End Type</option>
<option value="default">Default</option>
<option value="foil">Foil Sealed</option>
<option value="beads">Beads</option>
<option value="droppertip">Dropper Tip</option>
</select>


...needs to be:
Code: Select all
<select name="bottom-end" class="custom" id="myopt">
<option value="type" selected="selected">Bottom End Type</option>
<option value="default">Default</option>
<option value="foil">Foil Sealed</option>
<option value="beads">Beads</option>
<option value="droppertip">Dropper Tip</option>
</select>


...and add this code on the head section of your page:
Code: Select all
window.addEventListener?window.addEventListener('load',customOpt,false):
window.attachEvent('onload',customOpt); // FF : IE

function customOpt() {
   var opt = document.getElementById('myopt');
   opt.onchange = function () {
      var divs = ['bottom1','bottom2','bottom3','bottom4'];
      customOpt.resetDivs(divs);
      switch(this.value.toLowerCase()) {
         case 'foil':
            customOpt.domID(divs[1]).style.display='';
            break;
         case 'beads':
            customOpt.domID(divs[2]).style.display='';
            break;
         case 'droppertip':
            customOpt.domID(divs[3]).style.display='';
            break;
         default:
            customOpt.domID(divs[0]).style.display='';
            
      }
   }
   
   customOpt.resetDivs = function (arr) {
      for (var i = 0 ; i < arr.length; i++)
         this.domID(arr[i]).style.display='none';
   }
   
   customOpt.domID = function (el) {
      return document.getElementById(el);
   }
}


...and one last thing, remove "language="javascript"" here:
Code: Select all
<script type="text/javascript" language="javascript">


...that is deprecated.

Hope that helps.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Re: dropdown box image swap: firefox vs. IE7...grrr

Postby erkerr67 on Mon Apr 20, 2009 11:59 pm

fantastic. thank you so much, this helps a ton. hopefully i'll be good from here on out. i have a bumpy road ahead of me with the some different javascript-focused stuff with this same project but i'll try and tackle it :)
erkerr67
 
Posts: 10
Joined: Mon Apr 13, 2009 3:43 pm

Previous

Who is online

Users browsing this forum: No registered users and 5 guests