Search code examples
javascriptprototypejsdom-events

JavaScript works fine in any browser but Firefox?


Ok this is my JavaScript

<script type="text/javascript" language="JavaScript">
function manageCart(task,item) {
var url = 'managecart.php';
var params = 'task=' + task + '&item=' + item;
var ajax = new Ajax.Updater(
          {success: ''},
          url,
          {method: 'get', parameters: params, onFailure: reportError});
}

function reportError(request) {
$F('cartResult') = "An error occurred";
}

And this is HTML

<p>
<a href="javascript:void(0)" onclick="manageCart('add',83)">Add to cart</a>
</p>

This script doesn't work in Firefox, I've ran a few Firefox JS debuggers but they displayed no errors. I'm not so good in JavaScript so please help me if you can :) This script actually uses Prototype library if it will make things clearer.


Solution

  • I've spent more time in FireBug and found the error.

    Timestamp: 03.04.2013 10:36:38 Error: ReferenceError: invalid assignment left-hand side Source File: http://www.example.com/index.php Line: 413, Column: 18 Source Code:

    ('cartResult') = "An error occurred";
    

    Firefox desperately wanted for the statement to look like this:

    ('cartResult') == "An error occurred";