I am working on a shopping cart that will have a button next to each product allowing them to add the item into their car. I am trying to have a rollover effect to depress the button. (Yes, I will admit that its a loaded question).
I know how to process the submit action for the proper form, but I'm having a heck of a time trying to swap the images on the rollover. I can make it work when I only have one item on the page - but when I have more than one, that's when my problems begin.
JavaScript in '<HEAD>' of document
Sample for within loop (for multiple items)
'$i' is the loop variable
Thanks
I know how to process the submit action for the proper form, but I'm having a heck of a time trying to swap the images on the rollover. I can make it work when I only have one item on the page - but when I have more than one, that's when my problems begin.
JavaScript in '<HEAD>' of document
Code:
AddToCartDwn = new Image(150,75)
AddToCartDwn.src = "/images/addtocart-down.gif"
AddToCartUp = new Image(150,75)
AddToCartUp.src = "/images/addtocart.gif"
function FormSubmit(form_id, button_id) {
document.forms[form_id].btnAction.value = button_id;
document.forms[form_id].submit();
}
function btnDown(reference, id) {
// document.reference[id].src = eval(reference + "Dwn.src"); return true;
document.images[0].src = eval(reference + "Dwn.src"); return true;
}
function btnUp(reference, id) {
// document.reference[id].src = eval(reference + "Up.src"); return true;
document.images[0].src = eval(reference + "Dwn.src"); return true;
}
Sample for within loop (for multiple items)
'$i' is the loop variable
Code:
<form action="<?PHP echo(getenv(REQUEST_URI)) ?>" method="post" name="$i">
<IMG SRC="/images/addtocart.gif" HEIGHT="75" WIDTH="150" BORDER=0 ALT="Add to Cart" onMouseOver="btnDown('AddToCart', '$i')" onMouseOut="btnUp('AddToCart', '$i')" onClick="FormSubmit('<?PHP echo($i) ?>', 'Add To Cart')" name="$i">
<IMG SRC="/images/checkout.gif" HEIGHT="75" WIDTH="150" BORDER=0 ALT="Checkout" onMouseOver="btnDown('Checkout', '$i')" onMouseOut="btnUp('Checkout', '$i')" onClick="FormSubmit('$i','Checkout')" name="$i">
</FORM>
Thanks