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

ecross102301Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

webwyzsystemsCommented:
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

0
HonorGodSoftware EngineerCommented:
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

0
HonorGodSoftware EngineerCommented:
webwyzsystems, you and I did the same thing... :-)
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

ecross102301Author Commented:
I have implemented your suggestions but now how more errors. HonorGod what is line 8 that I need to removest
0
HonorGodSoftware EngineerCommented:
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

0
ecross102301Author Commented:
I have implemented the suggestions you requested and now have more syntax errors...please advise. As this made things worse.
0
HonorGodSoftware EngineerCommented:
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

0
ecross102301Author Commented:
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>
0
HonorGodSoftware EngineerCommented:
Did you use the "d.write" in the text, or the one in the code snippet (box)?

It looks like you use the wrong one.

Use this one:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HonorGodSoftware EngineerCommented:
Ah good.  Thanks for the code and points.

Good luck & have a great day
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JScript

From novice to tech pro — start learning today.