Forum Moderators: travelin cat

Message Too Old, No Replies

Safari javascript problem

         

csquirrel

2:07 pm on Nov 16, 2005 (gmt 0)

10+ Year Member



a new site I'm just testing works fine in all browsers except Safari (1.0.3, I'm not sure about more recent versions as my OS doesn't run them).

clicking on an image to run the functions 'moveLeft' and 'moveRight' using this tag:

<a onclick="javascript:moveLeft()" href="#">

doesn't seem to do anything. Code as below:

function display(m) {
document.all.productname.innerHTML = product[m][0];
document.all.price.innerHTML = "&pound;" + product[m][1];
document.all.number_of.innerHTML = (m+1) + " of " + product.length;
document.tshirt_big.src = "images/tshirt_big_" + (m+1) + ".jpg";
}

function moveLeft() {
if (n>0) {
n = n - 1;
display(n);
}
}

function moveRight() {
if (n<(number_of_items - 1)) {
n = n + 1;
display(n);
}
}

from searching I've done I realise Safari has some problems with javascript, I'm guessing that either Safari does not recognise the ID's of the elements I want changed, or does not recognise 'onclick'. Does anyone have any fixes?

thanks in advance

peterwalsham

11:59 am on Nov 21, 2005 (gmt 0)

10+ Year Member



At a very brief glance I would say don't use "document.all" in JavaScript, it's usually deprecated or unavailable.

Instead use "document.getElementById"

There are mentions of this in:
[developer.apple.com...]

=======================
Peter Walsham

[edited by: jatar_k at 5:07 pm (utc) on Nov. 23, 2005]
[edit reason] no sigs thanks [/edit]

csquirrel

1:36 pm on Nov 23, 2005 (gmt 0)

10+ Year Member



thanks, that works fine!