views:

77

answers:

2

What's the reason why some JavaScript functions won't work in Google Chrome but works fine in Mozilla Firefox?

Like this..

HTML code:
...

onkeyup="calculateTotal(this.value)" 
onclick="clickclear(this, '0')" onblur="clickrecall(this,'0')" value="0"

JS code:

function calculateTotal(price, quantity, cnt) {  
    if(quantity != ""){  
        var totalAmt = parseInt(document.getElementById('total['+cnt+']').value);  
        totalAmt = parseInt(quantity) * parseInt(price);

        document.getElementById('total['+cnt+']').value = totalAmt;
        document.getElementById('indicator').value++;
    }
    else{
        document.getElementById('total['+cnt+']').value = 0;
        document.getElementById('indicator').value--;

    }
}

And already included this:
jquery1.4.2.js

+4  A: 

You're calling the function

calculateTotal(this.value)

but your function is:

function calculateTotal(price, quantity, cnt)

I don't know why this DOES work in Firefox (I'm assuming they automatically supplied parameters or something), but your two functions do not match up.

codersarepeople
No, it's actually onkeyup="calculateTotal(<?php echo $row_item['item_price']; ?>, this.value, <?php echo $row_item['item_id'];?>)"
anonymous123
I just simplified it and I forgot to simplify the function. Actually, it's just for posting purposes that's why I removed some parameters just to show you guys the flow. It really works fine in Firefox.
anonymous123
A: 

From the html 4 spec:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

http://www.w3.org/TR/html401/types.html#type-name

I would therefore replace your use of square brackets in ids before trying anything else.

Ollie Edwards