SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Swap image - over state not retained?

    Hi there,

    I have created a navigation menu with dreamweaver mx. On roll over the image is swapped and onpress the over-state is retained, so the user knows where he is. When using dummy links, like <a href="#"> it works.

    But in my case i use
    Code:
    <a href="<?php echo $_SERVER['PHP_SELF']."?page=blah
    And the over-state is not retained, i know the page is being reloaded.

    Any tips how i can bypass this problem??

    Thnks

  2. #2
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You fell out of the double quotes in the href attribute and caused php to echo.
    Try this:

    PHP Code:
    <a href="<?php echo $_SERVER['PHP_SELF'].'?page=blah'?>">
    Blah</a>

    -xDev

  3. #3
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry,

    But i don't exactly get your point, furthermore i didn't post the complete code for my one of my href's (it is working):
    Code:
    <a href="<?php echo $_SERVER['PHP_SELF']."?page=hotel&hotelID=".$_REQUEST['hotelID']."&lang=".$_REQUEST['lang']; ?>"
    Because of the reload (hence PHP_SELF) i am not able to retain the over-state.

    Any more tips?

  4. #4
    SitePoint Addict BenANFA's Avatar
    Join Date
    Apr 2003
    Location
    Bath, UK
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by xDev
    You fell out of the double quotes in the href attribute and caused php to echo.
    Try this:

    PHP Code:
    <a href="<?php echo $_SERVER['PHP_SELF'].'?page=blah'?>">
    Blah</a>
    No, remember the PHP is parsed first so that any double quotes between the <?php ... ?> will have gone by the time the broswer gets to see the code.


    D-flyer

    You problem is that for that link the page has to be reloaded. To retain the overstate you need to find a way of making that state persist between pages, this means either sending it back to the server so that the page can be sent to the browser pre-configured with the state or storing it locally so that the page can re-read the state from the local storage once it has been reloaded.

    I can not think of anyway of doing the first since the state is dynamic, you might be able to use the second option by using some Javascript to store the state in a cookie.

    I think you may be better off asking this question in the PHP or Javascript forum.

  5. #5
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about that. I didn't understand what you were getting at.

    Basically you want an on state even though it may be the same page, just different request variables in the url. The logic behind it is simple. Do something like this:


    <img src="<?php echo ($_REQUEST['hotelID'] == whatever) ?
    'images/clicked.gif' : 'images/off.gif' ?>">


    Since each button will be either on or off based upon what the request string is in the url, you can test for a variable that you know to be unique if that menu item was clicked. Use the ternary right inside the src attribute and change it accordingly.

    -xDev

  6. #6
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, hmm i think i get (sort of ) but how do i accomplish this:

    My code for one menu button:
    Code:
    <td height="34"><a href="<?php echo $_SERVER['PHP_SELF']."?page=hotel&hotelID=".$_REQUEST['hotelID']."&lang=".$_REQUEST['lang']; ?>" onClick="MM_nbGroup('down','group1','subNav01','../images/<?php echo $imgSRC; ?>/<?php echo $imgSRC."_subNav1_over.gif"; ?>,1)" onMouseOver="MM_nbGroup('over','subNav01','../images/<?php echo $imgSRC; ?>/<?php echo $imgSRC."_subNav1_over.gif"; ?>','',1)" onMouseOut="MM_nbGroup('out')"><img src="../images/<?php echo $imgSRC; ?>/<?php echo $imgSRC."_subNav1.gif"; ?>" alt="subNav01" name="subNav01" width="119" height="30" border="0" onload=""></a></td>
    So now i think i must attach an $currentPage to the onClick statement. And reformulate the <img src > tag, to check if $currentPage is true and if so the over-state is chosen other wise the off state, right?

    So how do i prevent it to become a mess (code-wise ).

  7. #7
    SitePoint Guru D-flyer's Avatar
    Join Date
    Jan 2001
    Location
    Near a computer
    Posts
    782
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for the img src part i tried the following code
    Code:
    <img src="<?php ($currentPage == '1') ? "../images/EN/EN_subNav1_over.gif" : "../images/EN/EN_subNav1.gif"; ?>" alt="subNav01" name="subNav01" width="119" height="30" border="0" onload="">
    And in the corresponding <a href> i added
    Code:
    "&currentPage=1"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •