SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    error in javascript

    hi, a script is causing a trouble only in IE6 and not in any other browser.

    It just pointing to a Invalid tokien found at line 2 char 1

    All my requests going through the jobs page.

    when i make a call to the showjobs page, only then error occurs:
    here is my javascript:
    Code JavaScript:
    <script type="text/javascript" runat="server">
    DocImages = false; // Browser check for document.images Compatibility
    if(parseInt(navigator.appVersion)>=3) 
    {
      DocImages = true;
    }
      if(DocImages)
    {
    	for(i=0;i<2;i++){
    	  eval('btn' + i + '_on=new Image()');
    	  eval("btn"+ i +"_on").src = "buttons/btn_j_"+i+"_on.gif";
    	  eval('btn' + i + '_off=new Image()');
    	  eval("btn"+ i +"_off").src = "buttons/btn_j_"+i+"_off.gif";
    	}
    	for(i=3;i<=4;i++){
    	  eval('btn' + i + '_on=new Image()');
    	  eval("btn"+ i +"_on").src = "buttons/btn_j_"+i+"_on.gif";
    	  eval('btn' + i + '_off=new Image()');
    	  eval("btn"+ i +"_off").src = "buttons/btn_j_"+i+"_off.gif";
    	}
    	toc1=new Image();
    	toc2=new Image();
    	toc3=new Image();
    	toc_off=new Image();
    	toc1.src="templateimages/jobs_2nd_level_toc_1_on.gif";
    	toc2.src="templateimages/jobs_2nd_level_toc_2_on.gif";
    	toc3.src="templateimages/jobs_2nd_level_toc_3_on.gif";
    	toc_off.src="templateimages/jobs_2nd_level_toc_off.gif";
      }
    // swap for buttons
      function swap(num,dir){
    	if(DocImages){
    	if(dir ){
    	  eval("document.btn" + num).src= eval("btn" + num + "_on").src; 
    	  }
    	else {
    	  eval("document.btn" + num).src= eval("btn" + num + "_off").src; 
    	}
      }
    }
     
    var nn4 =(navigator.appName.indexOf("Netscape")>= 0 && parseFloat(navigator.appVersion)>=4)?1:0;
    var ie=(document.all)?1:0;
    var layerRef="null", styleSwitch="null"; 
     
    if (navigator.appName == "Netscape") {  
        layerRef="document.layers";  
        styleSwitch="";  
      }else{  
        layerRef="document.all";  
        styleSwitch=".style";  
      }  
    function init(){  
      var cur_w = getWindowWidth();
      var Xpos;
     
    <!--- <CFIF Form.action EQ "showjobs">
      if (cur_w < 760) { Xpos = 172; }
      else {
             if(ie) { Xpos = Math.ceil(cur_w/2 - 760/2 + 171-1); }
             if(nn4) { Xpos = Math.ceil(cur_w/2 - 760/2 + 171-1-7); }
           }  
      eval(layerRef+'["TextBodysr"]'+styleSwitch+'.left =' + Xpos);
    </CFIF>
     --->}  
    function getWindowWidth() {
     if(nn4) return window.innerWidth;
     if(ie) return document.body.clientWidth;
     return-1;
    }
    function resize()
    {
      var cur_w = getWindowWidth();
      var Xpos;
     <!---  <CFIF Form.action EQ "showjobs">
        if (cur_w < 760) { Xpos = 172; } 
        else { 
               if(ie) { Xpos = Math.ceil(cur_w/2 - 760/2 + 171-1); }
               if(nn4) { Xpos = Math.ceil(cur_w/2 - 760/2 + 171-1-7); }
             } 
        eval(layerRef+'["TextBodysr"]'+styleSwitch+'.left =' + Xpos);
      </CFIF> --->
    }
     
     
    <!--- <CFIF Form.action EQ "showjobs">
      window.onresize = resize;
    </CFIF> --->
    </script>

    u will see i have disabled or commented some tags in the javascript which are using <cfif tags in between them..

    when showjobs is called

    window.resize is called and above u will see the code for this.

    just then the Error:

    invalid token at char 2 lin1 found comes

    I tried dubugging but could not found the valid answer for this:

    plz help me thanks
    Last edited by spikeZ; Jan 22, 2008 at 09:38.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    runat=server means that this jscript isn't handled by the browser but by the server. That's probably the main error, try removing that.

    The script looks like it was written in 1998. It checks for NN4 and IE4. I think you should rewrite it completely for modern browsers.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •