Link to home
Start Free TrialLog in
Avatar of ecross102301
ecross102301

asked on

I have javascript syntax errors while trying to use a form

I am getting syntax errors in this script and I can't seem to find the errors. Can someone please help me?
<script type="text/javascript">
function utmx_section(){}function utmx(){}
(function(){var k='0790041258',d=document,l=d.location,c=d.cookie;function f(n){
if(c){var i=c.index0f(n+'=');if(i>-l){var j=c.index0f(';',i);return c.substring(i+n.length+1,j<0?c.length:j)}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;
d.write('<sc'+'ript' src="'+'http'+(l.protocol=='httpd:'?'s://ssl':'://www')+'.google-analytics.com'+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+'" type="text/javascript" charset="utf-8"><'/sc'+'ript>')})();
</script>
 
<script>

Open in new window

Avatar of webwyzsystems
webwyzsystems

I took a quick look - there were all kinds of syntax type errors. I tried quickly adding some whitespace to make it more readable - then went thru and fixed some of the weird things.

I don't have a lot of time unfortunately - hopefully this one is accurate:
<script type="text/javascript">
function utmx_section(){}
 
function utmx(){}
 
function (){
  var k='0790041258';
  d=document;
  l=d.location;
  c=d.cookie;
  function f(n){
  if(c){
       var i=c.index0f(n+'=');
       if(i>-l){
          var j=c.index0f(';',i);
          return c.substring(i+n.length+1,j<0?c.length:j);
	 }
        }
    }
    var x=f('__utmx');
    xx=f('__utmxx');
    h=l.hash;
    d.write('<sc'+'ript src="'+'http'+(l.protocol=='httpd:'?'s://ssl':'://www')+'.google-analytics.com'+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+'" type="text/javascript" charset="utf-8"><'+ '/sc'+'ript>');
}
</script>

Open in new window

Avatar of HonorGod
Why in the world are you writing, or using code like this?

Line 8 is unneeded/wrong

And 5 should probably be:
    d.write( '<sc' + 'ript' src= "'+'http'+(l.protocol=='httpd:'?'s://ssl':'://www')+'.google-analytics.com'+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+' type="text/javascript" charset="utf-8"><'/sc'+'ript>' )

Open in new window

webwyzsystems, you and I did the same thing... :-)
Avatar of ecross102301

ASKER

I have implemented your suggestions but now how more errors. HonorGod what is line 8 that I need to removest
Your line 8 above is the last in your "snippet", i.e.,


unless, of course, you have script code after that....
<script>

Open in new window

I have implemented the suggestions you requested and now have more syntax errors...please advise. As this made things worse.
Well, webwyzsystems and I started down the same route, and expanded/formatted it in a similar fashion.

The big problem appears to the the content of the d.write() call.

It starts like this:

'<sc'+'ript' src="'

which is a problem, because the first string (i.e., '<sc' is then concatentated with the next string (i.e., 'ript').  So far, so good.  This is equivalent to:

'<script'

Then, we start running into problems. because the src=" should really be in a string.  So, let's see if we can change the start to:

'<sc'+'ript src="'

This is then followed by + and another string, so this may be alright.

Continuing in this way, it appears that this may be the proper d.write() line:

d.write( '<sc'+'ript src="'+'http'+(l.protocol=='httpd:'?'s://ssl':'://www')+'.google-analytics.com'+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+'" type="text/javascript" charset="utf-8"></sc'+'ript>' )
<script type="text/javascript">
  function utmx_section(){
  }
  function utmx(){
  }
  ( function() {
      var k = '0790041258', d = document, l = d.location, c = d.cookie;
      function f( n ) {
        if( c ) {
          var i = c.index0f( n + '=' );
          if ( i >- l ) {
            var j = c.index0f( ';', i );
            return c.substring( i + n.length + 1, j < 0 ? c.length : j )
          }
        }
      }
      var x = f ('__utmx'), xx = f( '__utmxx' ), h = l.hash;
      d.write( '<sc'+'ript' src="'+'http'+(l.protocol=='httpd:'?'s://ssl':'://www')+'.google-analytics.com'+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+'" type="text/javascript" charset="utf-8"><'/sc'+'ript>' )
    }
  )();
</script>

Open in new window

Now we are back to the original error

Syntax error: Missing ) after argument list
See: src="'+'http'+(l.protocol=='httpd:'?'s://ssl':'://www')+'.google-analytics.com'+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='+new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+'" type="text/javascript" charset="utf-8"><'/sc'+'ript>' )
    }
  )();
</script>
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ah good.  Thanks for the code and points.

Good luck & have a great day