We help IT Professionals succeed at work.
Get Started

JS Error -> Split is not a function

redzoneglobal
on
6,551 Views
Last Modified: 2008-01-09
I'm teaching myself javascript, as we have decided to develop our own analytics tracking to integrate into our analytics db.  We had previously been using a 3rd party to provide tracking technology.  So, this is my first dive into javascript, with my experience mostly in VB .net/asp and SQL.  I was making good progress, and then ran into this issue.  Javascript tested through: var broken_info = cookieValue.split(":")

When the browser executes this line I get: cookieValue.split is not a function in Firefox error console.

Here is the complete javascript (which is housed in a js file) and is called from the javascript at this URL:  http://www.searchmarketingtools.com/tester.html?source=testengine&kw=test+keyword

//<!-- Tracking Code v1.00 - All rights reserved -->

function Randomstring()
{
var chararr="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

var rndstr=""
for(i=0;i<10;i++)
{

      rndstr=rndstr+chararr.charAt(Math.round(Math.random()*62)-1)
}
    id = rndstr;
    return rndstr;
}
function Setcookie()
{
    var _d=new Date();
    _d.setTime(_d.getTime()+31536000000);
      expires=_d
    var fcnv = "SMTstatbuilder="+"id:"+Randomstring()+"; path=/; expires="+expires;
    document.cookie = fcnv;


}
function readCookie(name) {
      if (document.cookie == '') {
   // there's no cookie, so go no further
      return false;
      } else {
   // there is a cookie
      var firstChar, lastChar;
      var theBigCookie = document.cookie;
      firstChar = theBigCookie.indexOf(name);
   // find the start of 'name'
      if(firstChar != -1)  {
   // found cookie
      firstChar += name.length + 1;
   // skip 'name' and '='
      lastChar = theBigCookie.indexOf(';', firstChar);
   // Find the end of the value string (i.e. the next ';').
      if(lastChar == -1) lastChar = theBigCookie.length;
      return unescape(theBigCookie.substring(firstChar, lastChar));
            } else {
   // If there was no cookie of that name, return false.
      return false;
      }
    }
}
var id
var cookieValue = readCookie('SMTstatbuilder');
if(cookieValue == "false"){Setcookie}
else {
     var broken_info = cookieValue.split(":")
    id = broken_info[1];
}
******************************************************************
From all the reference/documentation I have reviewed, split is a valid string function.  Why am I getting this error?
Comment
Watch Question
CERTIFIED EXPERT
Expert of the Year 2008
Top Expert 2008
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE