Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Dynamically switch styles

  1. #1
    Join Date
    Nov 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamically switch styles

    I decided I was going to learn CSS, JavaScript, and PHP. Currently I am in the process of starting a web page. I would like to use JavaScript to choose a style from a drop down box and dynamically switch to a different style sheet depending on the choice. Right now, I can only set it up with one style sheet. The part I'm really having a hard time is with my images as well. Any suggestions are greatly appreciated.

    Thanks.

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Hmmm closest thing I can think of: http://www.dynamicdrive.com/dynamici...etswitcher.htm

  3. #3
    Join Date
    Nov 2005
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    what is going on with your images? perhaps I can help with that.

  4. #4
    Join Date
    Nov 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    So I've got it so that I can dynamically change the css with a drop down box, change all the images, and set a cookie so that the css travels from page to page. But my images revert to the default when traveling from page to page and I'm not sure how to keep them staying with the css. For instance:

    default is "Pink.css" with a button "pink.jpg"
    when I switch to "Blue.css" the first time, it will change the button to "blue.jpg" but when I navigate to a different page on the site, it will stay "Blue.css" but the button will be "pink.jpg". How do I change that?

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You need to store that in the cookie too, and construct the images dynamically. Be careful to preserve compatibility with non-JS browsers.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Nov 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Do you have some good suggestions on where to look to dynamically change the image src?

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can manipulate img.src as with any other string, where "img" is an image object.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Nov 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I gave up

    I was given the suggestion of setting the size of a link and setting the background image to the image for my button. It works a lot more smoothly and it changes when I change my css.

    so I have
    a{background-image: url('image.jpg');} <!--valid-->
    you can't set the image source through a CSS
    img{src: url('image.jpg');} <!--not valid-->

    This way I still only need one cookie for the CSS and not multiple cookies for the images.

    The images that aren't links I put as divs.

    http://www.rustipher.com/~loni/

  9. #9
    Join Date
    Nov 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I can't seem to find where I can set the "selected" option for my css dropdown box. Whenever I go to a different page or style, it reverts back to Cutesy. Do you have a suggestion or does it need to be through a cookie or script?

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Oh, I see. I'm sorry, but you can't change image srcs with CSS. I was using Javascript. I suppose you could use divs with background-images; is that what you're referring to above?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •