• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1024
  • Last Modified:

Javascript - set variable value from onMouseOver event

Can someone please show me how to set a variable via a onMouseOver event and then pass this value to a function via a Buy button.  

  onMouseOver='image.src="<?php echo $image2; ?>"; color = 1;'
  onMouseOver='image.src="<?php echo $image2; ?>"; color = 2;'

Buy Button  
onClick="location.href='javascript:AddItem(<?php echo $rs_prods['PID']?>,1,color)'"

function AddItem($PID, $qty, color)
      {
            var item = $PID;
            var qty = $qty;
            var color = color;

            self.location = "addtocart.php?action=add_item&id="+item+"&qty="+qty+"&color="+color;
            }
0
sabecs
Asked:
sabecs
1 Solution
 
Michel PlungjanIT ExpertCommented:
 onMouseOver='image.src="<?php echo $image2; ?>";currentColor = 1;'
  onMouseOver='image.src="<?php echo $image2; ?>";currentColor = 2;'

Buy Button  
onClick="location.href='javascript:AddItem(<?php echo $rs_prods['PID']?>,1,currentColor)'"

var currentColor=""; // or defaultcolor here...
function AddItem($PID, $qty, color)
      {
            var item = $PID;
            var qty = $qty;
            color = (color!="")?color:"defaultcolor";

            self.location = "addtocart.php?action=add_item&id="+item+"&qty="+qty+"&color="+color;
            }
0
 
sabecsAuthor Commented:
Thanks mplungjan, perfect.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now