Forum Moderators: open

Message Too Old, No Replies

changing buttons depending on the cart status

changing buttons depending on the cart status

         

fototex

12:37 pm on Jul 11, 2009 (gmt 0)

10+ Year Member




Hi frieds,

I have a shopping cart script which works very good.(cart.js) it is also included in some pages.

I have a script in it checking if the cart is empty or not.
-------------------------------------
function Cart_is_empty( ) {
iNumInCart = GetCookie("NumberOrdered");

if ( iNumInCart == null ) iNumInCart = 0;

if ( iNumInCart == 0 ) return true;

return false;
--------------------------------------

Below the cart I have two buttons (jpegs):
"checkout" and "continue shopping"

What I am trying to achieve is:
I have a third button "begin shopping" which I want to make it appear in the cell of the "continue shopping" button if the cart is empty. If the cart is not empty, the "continue shopping" button should appear.

So in my cart page I wrote the following code but could not make it work:

<script language="javascript" type="text/javascript">
if ( Cart_is_empty()) {
document.getElementById('cartbtn1')="<../webimages/icons/begin.gif>";
}
else {
document.getElementById('cartbtn1')="<../webimages/icons/continue.gif>";
}
</script>

It gives me the error message:

"wrong number of arguments or invalid property assignment"

Any ideas what might be missing or wrong?

fototex

12:40 pm on Jul 11, 2009 (gmt 0)

10+ Year Member



Meanwhile 'cartbtn1' is the cell ID where the exchanging buttons will appear respectively.

daveVk

1:19 pm on Jul 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if this refers to an image

document.getElementById('cartbtn1')

you need

document.getElementById('cartbtn1').src = "../webimages/icons/begin.gif";

fototex

5:04 pm on Jul 11, 2009 (gmt 0)

10+ Year Member



daveVK, this works excellent,

Many thanks for your guidance.

fototex

11:55 am on Jul 12, 2009 (gmt 0)

10+ Year Member



One more newbie question:

How to achieve that the checkout button to dissappear in its 'cartbtn2' field if there are no products in the cart?

document.getElementById('cartbtn1').src = "";

did not help

Thanks

daveVk

1:06 pm on Jul 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.getElementById('cartbtn1').style.display='none';

to get it back

document.getElementById('cartbtn1').style.display='inline';