Jump to content

Would like to change Add to cart background color after click(or after adding product to cart)


PrabuSS

Recommended Posts

Hi

 

I Would like to change Add to cart background color after click(or after adding product to cart) in product listing and product details page. Now I've added following code to achieve this on product-list.tpl. But its required to refresh the page to see the color changes. I need to change Color of cart button when product is added to cart, not just when refresh the site

{if ($cart->containsProduct($product.id_product, $product.id_product_attribute))}
									
	<a class="button ajax_add_to_cart_button cart_button" href="{$link->getPageLink('cart',false, NULL, "add=1&id_product={$product.id_product|intval}&token={$static_token}", false)|escape:'html':'UTF-8'}" rel="nofollow"  title="{l s='Add to cart'}" data-id-product="{$product.id_product|intval}" style="background-color: #83E02F;">
										
		<span>{l s='Add to cart'}</span>
       </a>

<!-- / check if you have this product in cart -->

{else}
									
       <a class="button ajax_add_to_cart_button cart_button" href="{$link->getPageLink('cart',false, NULL, "add=1&id_product={$product.id_product|intval}&token={$static_token}", false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Add to cart'}" data-id-product="{$product.id_product|intval}" tabindex="1">
										
		<span>{l s='Add to cart'}</span>
	</a>
										
{/if}

URL : http://www.drucken24.at/465-intec

 

PS Version : 1.6.1.11

 

Screens attached.

 

Please any one

post-618037-0-87511700-1495116034_thumb.png

post-618037-0-29083100-1495116042_thumb.png

Edited by Prabukaran (see edit history)
Link to comment
Share on other sites

 

Try to implement this one:


<button type="button" onclick="changeBG()">Set background color</button>

<div id="myDIV">
  <h1>Hello content</h1>
</div>


<script>
function changeBG() {
    document.getElementById("myDIV").style.backgroundColor = "red";
}
</script>

Thanks for your reply.

 

I've implemented your javascript code on my Cart button in product-list.tpl. But its not working. I think ajax call on cart button has been blocked this code.

<script type="text/javascript">
function changeBG() {
    document.getElementById("cartbutton").style.backgroundColor = "#83E02F";
}
</script>


<a id="cartbutton" class="button ajax_add_to_cart_button cart_button" href="{$link->getPageLink('cart',false, NULL, "add=1&id_product={$product.id_product|intval}&token={$static_token}", false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Add to cart'}" data-id-product="{$product.id_product|intval}" onclick="changeBG()">


You can use page source to see my script in this page http://www.drucken24.at/465-intec

 

Please help.

Edited by PrabuSS (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...