views:

2159

answers:

3

I get Error "Object Expected" on line 1, char 1 (where-ever this is) on my script here in IE7. It works fine in Firefox, and the error console prints nothing.

I tried multiple ways to call my function but none works:

<a href="javascript:doit()">Turingmaschine starten</a>
<a href="#" onclick="doit()">Turingmaschine starten</a>

What could be the problem?

<script type="text/javascript" language="JavaScript">

var state;
var index;
var program;
var data;

const S=0;
const X=1;
const S2=2;
const X2=3;
const M=4;
const E="SE";

function doit()
{
    state=document.getElementById("stat").value;
    program = document.getElementById("prog").value.split("\n");
    index = document.getElementById("dat").value.indexOf("Z")>>1;
    data = document.getElementById("dat").value.replace(/Z,/, "").split(",");

    for (var i = 0; i<program.length; i++)
    {
        program[i]=program[i].split(",");
    }

    while(state!=E)
    {
        var i;
        for (i = 0; i<program.length; i++)
        {
            if (program[i][S]==state && program[i][X]==data[index])
            {
             state = program[i][S2];
             data[index] = program[i][X2]
             index+= parseInt(program[i][M]);

             data.splice(index,0,"Z");

             if (data[data.length-1]!="*")
             {
              data.push("*");
          }
          if (data[0]!="*")
          {
              data.unshift("*");
              index++;
                }
             document.getElementById("out").value+=state+": "+data+"\r\n";

             data.splice(index,1);

             break;
            }
        }

        if (i==program.length)
         break;
    }

    document.getElementById("out").value+="Done.\r\n";
}

</script>
A: 

Is this code in a .js file? if so, try removing the tag.

it may be interpreting the tag as ( ____ < script ) and expects there to be a comparable object on the left side of a "less than" operation.

Matt Dunnam
no its in the head section of the same html file
codymanix
+5  A: 

Const is not supported by IE. It is specific to Firefox and Opera 9.0+. Also, if you post what this code is for, perhaps we can help refactor it.

https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statements/const#Description

Chetan Sastry
A: 

I had a similar problem, All I did was change:

<script language="javascript" type="application/javascript" src="abc.js"></script>

TO THIS:

<script language="javascript" src="abc.js"></script>

So just removed type="application/javascript" part.

Cheers