Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Can someone take a look at this mouseover code


julianpuje

Recommended Posts

Posted

Hi all

 

I've created some header buttons/tabs for my site using the code below. There are only two buttons there at the moment, but more appear depending on what you are doing. ie, if logged in, if anything in your cart etc etc.

Does anybody know how or what to change so the selected page stays on the mouseover image?

ie, currently the button swaps when you mouseover and changes back when you move your mouse away which is correct. If i click/select that button, how do i get the mouseover button to stay so you know that is the page you are on. I hope that makes sense.

ps: i am no coder, i have tweaked and changed this to get it to work, so any help with implementing any code/comments appreciated.

 

Any help also greatly appreciated.

Thanks

Julian

 

Heres the code for one of the buttons:-

<a onmouseover="home.src='<?php echo DIR_WS_IMAGES; ?>home1.gif';" 
  onmouseout="home.src='<?php echo DIR_WS_IMAGES; ?>home.gif';" 
  href="<?php echo tep_href_link(FILENAME_DEFAULT); ?>">
  <img border=0 alt="www.jbleisure.co.uk Home Page" name=home src='<?php echo DIR_WS_IMAGES; ?>home.gif'>
</a>

A little knowledge is dangerous, I SHOULD KNOW.

If Life Begins At 40, What ends????

Posted

before you display the 3rd image that is not on a handler you need to check for the condition (in your case the page you're in.

 

So lets say to check for the index

if (basename($PHP_SELF) == FILENAME_DEFAULT ) && !isset($HTTP_GET_VARS['products_id'] && 
!isset($HTTP_GET_VARS['cPath']) ) {
 $dynamicImage = DIR_WS_IMAGES . 'home_bright.gif';
} else {
 $dynamicImage = DIR_WS_IMAGES . 'home.gif';
}

 

and then your code:

<a onmouseover="home.src='<?php echo DIR_WS_IMAGES; ?>home1.gif';" 
onmouseout="home.src='<?php echo DIR_WS_IMAGES; ?>home.gif';" 
href="<?php echo tep_href_link(FILENAME_DEFAULT); ?>">
<img border=0 alt="www.jbleisure.co.uk Home Page" name=home src='<?php echo $dynamicImage; ?>'></a>

 

just double check for syntax errors havent tried it here

Posted

Thanks for the reply Mark.

I could only get your suggestion to work like:

<?php
if (basename($PHP_SELF) == FILENAME_DEFAULT ) {
$dynamicImage = DIR_WS_IMAGES . 'home1.gif';
} else {
$dynamicImage = DIR_WS_IMAGES . 'home.gif';
} ?>

by removing the &&. But it does appear to be working now for all the buttons :thumbsup:

The only problem i can see is that when you mouseover the button it changes it's state back even if not selected? any ideas how i can fix the state when you are on that page?

 

Thanks again

 

Julian

 

Oh yes, i forgot, i still need to add the cpath and product_id but i get a Boolean error? this is obviously so i can navigate away from that page and the button will change it's state back to normal!

 

Thanks again

A little knowledge is dangerous, I SHOULD KNOW.

If Life Begins At 40, What ends????

Posted

Sorry Julian, I forgot the closing bracket on the first isset Should been like:

 

if( (basename($PHP_SELF) == FILENAME_DEFAULT ) && !isset($HTTP_GET_VARS['products_id']) &&

!isset($HTTP_GET_VARS['cPath']) ) {

Posted
Thanks for the reply Mark.

The only problem i can see is that when you mouseover the button it changes it's state back even if not selected? any ideas how i can fix the state when you are on that page?

 

Thanks Mark, that does work now. But i still get the above problem? any ideas on that one?

Thanks again

 

Julian

A little knowledge is dangerous, I SHOULD KNOW.

If Life Begins At 40, What ends????

Posted

Ok yes I see it in your page because the events (over/out) are left for the button, although you're in the page where the button suppose to always be selected.

 

So for the home button location:

 

if( (basename($PHP_SELF) == FILENAME_DEFAULT ) && !isset($HTTP_GET_VARS['products_id']) && 
!isset($HTTP_GET_VARS['cPath']) ) {

 echo '<img border=0 alt="www.jbleisure.co.uk Home Page" name=home src="home1.gif"></a>'

}

 

so in this case if you are on the home page there is no need for the onmouseover/onmouseout handlers the button stays on all the time. And you can add an "else" statement where you have the other code with the events. Now since you will have a lot of images and buttons its better to setup a table or a class to handle all cases in a simple way based on the global variables that are in the HTTP_GET_VARS and HTTP_POST_VARS arrays.

Posted

Thanks again Mark. But i really don't understand what you mean or where to put the last piece of code you posted etc etc. :blush:

 

Thanks

Julian

A little knowledge is dangerous, I SHOULD KNOW.

If Life Begins At 40, What ends????

Posted

Well you do not want the events (onmouseover, onmouseout) to be included for the buttons that are enabled on a specific page. So for your home page you have a home button.

 

So the whole part of the code would be in this example:

 

if( (basename($PHP_SELF) == FILENAME_DEFAULT ) && !isset($HTTP_GET_VARS['products_id']) && 
!isset($HTTP_GET_VARS['cPath']) ) {

echo '<img border=0 alt="www.jbleisure.co.uk Home Page" name=home src="home1.gif"></a>';

} else {
echo '<a onmouseover="home.src='<?php echo DIR_WS_IMAGES; ?>home1.gif';" 
onmouseout="home.src='<?php echo DIR_WS_IMAGES; ?>home.gif';" 
href="<?php echo tep_href_link(FILENAME_DEFAULT); ?>">
<img border=0 alt="www.jbleisure.co.uk Home Page" name=home src='<?php echo $dynamicImage; ?>'></a>';
}

Posted

Get it now! sorry.

I notice you've placed a closing </a> in this line :

echo '<img border=0 alt="www.jbleisure.co.uk Home Page" name=home src="home1.gif"></a>';

But i can't see where the <a starts to close it.

 

Thanks again

 

Julian

 

ps: just downloaded your countries contribution, been after something like that for a while as i only sell in the UK :thumbsup: Hopefully it will do what i want.

A little knowledge is dangerous, I SHOULD KNOW.

If Life Begins At 40, What ends????

Posted

yes, you do not need that closing </a> I just copied the code from above and modified it so I missed it.

 

Now these "if" comparisons can complicate the code a lot if you use many buttons on each page. You could setup a table with a separate function or class (like a matrix maybe) to retrieve the button state and setup a function to assign the event handlers based on the page.

 

PS Thanks. If you find problems with the active countries please post the details on the support thread, I should be able to fix it. :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...