SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    532
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using PHP to change CSS element values?

    Can PHP be used in a similar way (or rather, to achieve a similar end result) as javascript that is used to alter CSS element values? For example, using PHP to achieve the same result as this does (in this case, changing the display style of a specific element to 'none'):

    Code:
    document.getElementById('Menu'+Menu[i]).style.display = 'none';

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i don' tsee any problems. you can also use dynamic style sheets like

    style_sheet.php
    PHP Code:
    <?php
     header
    ('Content-Type: text/css');
    ?>
    .text{color:black;}
    this way you can also store user preferneces in database and then retirve them and use them in one style sheet which is dynamically changing with each diffferent user. something like
    style_sheet.php
    PHP Code:
    <?php
     header
    ('Content-Type: text/css');
    // mysql_connect() here
    // mysql_query() here
    $color $row['color'];

    ?>
    .text{color:<?php echo $color;?>;}
    i saw PHPMyAdmin doing that and i like it.(not the database part)

    hope this helps
    ---------------------------
    Errors = Improved Programming.
    My Site

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    532
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think that's quite what I am looking for, but maybe I am misunderstanding it somewhat.

    The javascript that I was looking to replace changes the style of a specific element on certain pages, depending on their location. So, if the user loads up a page in /Folder1, they get a different result than if they load up a page in /Folder2.

    More specifically, I need to load a specific menu depending on where on the site the user is. I have an array in PHP that I use to determine the location of the page, and to set a variable that is used to identify the location. My idea was to have an if statement for each menu, which in the case that the variable is set to the right value, would change the display for that specific menu from none to block.

    Currently, this display change is done through a combination of PHP and javascript, but I think that all PHP would be a bit faster and neater.

  4. #4
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you want to get that elelment by elementId then you can do it with JavaScript NOT with PHP because php is server side and cannot change elements by IDs on client side. so, you have to use combination of JavaScript and PHP. In this case yo uwill generate JavaScript with PHP, so you'll get teh power of both. somthing like
    PHP Code:
    <?php 
      $menu
    [0] = 'something';

    ?>
    document.getElementById('Menu'+<?php echo $menu[0];?>.style.display = 'none';
    hopefully i am right this time.
    ---------------------------
    Errors = Improved Programming.
    My Site

  5. #5
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    532
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, I see. I had hoped there was some way (not necessarily with elementID -- any solution that changes the display from none to block would work) I could do it entirely in PHP, because the PHP+javascript solution isn't ideal. It takes a bit too long for the menu to load, plus the script has to be inserted into each page rather than stored in an external .js file.

    Thanks for explaining.


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
  •