Hi, I have a schedule updater that is running perfectly in firefox, but slowly in IE7 (and probably IE6 as well). You can see the script in action at:
http://www.jobvid.com/CustomizeNewSchedule.php

Any help would be greatly appreciated! The code is below...

Thanks,

Dave

<script type="text/javascript">
function changecolor(Id,ctrlhide){
var current = document.getElementById(ctrlhide).value;
if (current == '#7CF67F'){
document.getElementById(Id).style.backgroundColor = '#E7E401';
document.getElementById(ctrlhide).value = '#E7E401';
var stopscript = 1;
}
if (current == '#E7E401' & stopscript != 1){
document.getElementById(Id).style.backgroundColor = '#0067F2';
document.getElementById(ctrlhide).value = '#0067F2';
var stopscript = 1; 
}
if (current == '#0067F2' & stopscript != 1){
document.getElementById(Id).style.backgroundColor = '#C0C0C0';
document.getElementById(ctrlhide).value = '#C0C0C0';
var stopscript = 1;
}
if (current == '#C0C0C0' & stopscript != 1){
document.getElementById(Id).style.backgroundColor = '#7CF67F';
document.getElementById(ctrlhide).value = '#7CF67F';
}
}
</script>

Recommended Answers

All 5 Replies

Hi daveg,

Try to apply the following changes inside your script:

<script type="text/javascript">
var viaID = Boolean( document.getElementById );

var changecolor = function( Id, ctrlhide ) {
var stopscript;
var current = (( viaID ) ? document.getElementById( ctrlhide ) : document.all[ ctrlhide ] );
var el = (( viaID ) ? document.getElementById( Id ) : document.all[ id ] ).style;

   if ( current.value === '#7CF67F' ) {
      el.backgroundColor = '#E7E401';

      current.value = '#E7E401';
      stopscript = 1;
   }
 else if (current.value === '#E7E401' && stopscript !== 1){
      el.backgroundColor = '#0067F2';
      current.value = '#0067F2';
      stopscript = 1; 
   }
 else if (current.value === '#0067F2' && stopscript !== 1 ) {
      el.backgroundColor = '#C0C0C0';
      current.value = '#C0C0C0';
      stopscript = 1;
}
 else { 
      if ( current.value == '#C0C0C0' && stopscript !== 1) {
         el.backgroundColor = '#7CF67F';
         current.value = '#7CF67F';
   
   }
   }
}
;
</script>

I will give that a try. I won't be able to make the changes until later tonight, but I'll let you know how it goes. Thanks for the help!

-Dave

essential,

Thanks again for the advice. I have made the changes you suggested, but the code is still sluggish in IE6 and IE7. I think it might be slightly faster, but nowhere near as fast as in Firefox. Any other suggestions as to how I might go about optimizing the code for IE?

Thanks,

Dave

Hi all,

I tried the code below instead...should be even more optimized. But still not fast enough in IE.

Any suggestions?

Thanks in advance,

Dave

<script type="text/javascript">
var viaID = Boolean( document.getElementById );
var changecolor = function( Id, ctrlhide ) {
var stopscript;
var g = '#7CF67F';
var y = '#E7E401';
var b = '#0067F2';
var z = '#C0C0C0';
var current = (( viaID ) ? document.getElementById( ctrlhide ) : document.all[ ctrlhide ] );
var el = (( viaID ) ? document.getElementById( Id ) : document.all[ id ] ).style;

   if ( current.value === g ) {
      current.value = y;
      el.backgroundColor = y;
   }
 else if (current.value === y){
      current.value = b;
	  el.backgroundColor = b; 
   }
 else if (current.value === b) {
      current.value = z;
	  el.backgroundColor = z;
}
 else { 
      if ( current.value == z) {
         current.value = g;
		 el.backgroundColor = g;
   
   }
   }
}
;
</script>

Hi dave,

Maybe this <LINK> might help you out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.