Jump to content

undefined help. One function works in IE and not Firefox & vice versa


ballhogjoni

Recommended Posts

This is the line of code that contains the output from the function below:

 

<div id="colorize" class="timeClass">RSVP WITHIN <span id="theTime"></span></div>

 

 

This is the line that is "undefined" in the below function: if (document.getElementById) { theTime.innerHTML = time; }

 

In firefox I get this error: theTime is not defined. In IE this works fine

 

function countDown() {
  sec--;
  if (sec == -01) {
    sec = 59;
    min = min - 1;
  } else {
   min = min;
  }
if (sec<=9) { sec = "0" + sec; }
  time = (min<=9 ? "0" + min : min) + ":" + sec;
if (document.getElementById) { theTime.innerHTML = time; }
  SD=window.setTimeout("countDown();", 1000);
if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); alert("Your Time Has Expired, Please Close This Box For More Time."); }
}

 

In firefox I get this error but works just fine, In IE this doesn't work:  document.getElementById("colorize") has no properties for this code.

 

var c = new Array("#FFFF33", "#FFFF00", "#FFFF33", "#FFFF55", "#BDB8BC", "#FFFF55", "#FFFF33", "#FFFF00", "#FFFF33", "#FFFF55", "#BDB8BC", "#FFFF55", "#FFFF33", "#FFFF00", "#FFFF33", "#FFFF55", "#BDB8BC", "#FFFF55", "#FFFF33", "#FFFF00", "#FFFF33", "#FFFF55","#BDB8BC", "#FFFF55", "#FFFF33", "#FFFF00", "#FFFF33", "#FFFF55", "#BDB8BC", "#FFFF55", "#FFFF33", "#FFFF00", "#FFFF33", "#FFFF55", "#BDB8BC", "#FFFF55", "#FFFF33", "#FFFF00", "#FFFF33", "#FFFF55", "#BDB8BC", "#FFFF55", "#FFFF33", "#FFFF00", "#FFFF33", "#FFFF55", "#BDB8BC", "#FFFF55", "#FFFF33", "#FFFF00", "#FFFF33", "#FFFF55", "#BDB8BC", "#FFFF55", "#FFFF33", "#FFFF00", "#FFFF33", "#FFFF55", "#BDB8BC", "#FFFF55", "#FFFF33", "#FFFF00", "#FFFF33", "#FFFF55");

x = 0;

function bg_eff()
   {
   var col_val = c[x];
   document.getElementById("colorize").style.background = col_val;
   x++;
   if (x == 64)
      {
      document.getElementById("colorize").style.background="#BDB8BC";
  clearInterval(change_bg);
      }
   }
change_bg = setInterval("bg_eff()", 200);

Link to comment
Share on other sites

For the first function, your problem is easy - theTime hasn't been defined. It says so right in the error! You are trying to use something called theTime, but you haven't told javascript what that is anywhere, so it cant do anything with it.

 

The second one is a little different. I'm not sure why its not working, but the way you are trying to do it isn't the most ideal method anyways. You create a CSS class that has the properties that you want, and then rather than changing the style, change the classname.

 

With firefox you change the classname using

object.setAttribute("class","class_name_goes_here")

 

and with IE you set it like this:

 

object.className="class_name_goes_here"

Link to comment
Share on other sites

For the first function, your problem is easy - theTime hasn't been defined. It says so right in the error! You are trying to use something called theTime, but you haven't told javascript what that is anywhere, so it cant do anything with it.

 

How would I define theTime. I am a newb with javascript.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.