SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast JohnShaft's Avatar
    Join Date
    Oct 2002
    Location
    England
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dropdown Box to Change Skin (need help!)

    Hi, I currently have a dropdown box on my site http://www.horrorexpress.com that I use to change skins. I basically attach the skin variable (it's a PHP site) to the end of the URL manually (in what now seems a very ugly way).
    I've been doing it this way for months, but now I'm switching to SE Friendly URL's this way will no longer be possible. Also it will help to clear up pages in my Search Engine results.

    So basically I guess I want to use Javascript to POST the variable (skin name) I need sending, so that it doesn't change the URL or Page?

    I know next to nothing about Javascript, so I really would appreciate any help from someone who does.
    Thanks.
    HorrorExpress.com - all the latest Horror Movie Reviews and News

  2. #2
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    best to use cookies for that sort of thing, it's the only way to store variables throughout your site. (or frames, but they are harder to get SE friendly)
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  3. #3
    SitePoint Enthusiast JohnShaft's Avatar
    Join Date
    Oct 2002
    Location
    England
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I do use cookies Mark.
    How I've been doing it is checking for "setskin=skinname" in the query string, if it's there set the cookies.
    But like I said I want to do it without attaching anything to the query string...
    http://www.mugglenet.com is a site that does it by sending you back to the same page (which I do) but without adding any query string (which I can't).

    No-one have experience of this? I'm really desperate to get it sorted, especially for when I decide to go SE Friendly with mod_rewritten URLs.
    (Add: actually they did, I've just noticed they've changed it)
    HorrorExpress.com - all the latest Horror Movie Reviews and News

  4. #4
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi John,

    So you want to "post" the name of the skin when people selects something in the dropdown menu? Please put this javascript in the <head>:
    Code:
    <script type="text/javascript" language="JavaScript">
    function changeSkin( selectObj) {
      if( selectObj.options[ selectObj.selectedIndex ].value.length > 2) {
        selectObj.form.submit();
      }
    }
    </script>
    And change the <form> code to:
    Code:
    <form method="post"> 
    		<select NAME="setskin" onchange="changeSkin(this);"> 
    		<option VALUE="">Choose Skin</option>
    		<option VALUE="blackout">Halloween Blackout</option>
    		<option VALUE="violet">Violet Demise</option>
    		</select> 
    </form>
    HTH~
    (Edit: made slight adjustments to the code, ripped out "style" in the select tag so the code doesn't make you scroll horizontally.)

  5. #5
    SitePoint Enthusiast JohnShaft's Avatar
    Join Date
    Oct 2002
    Location
    England
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    WOW.
    I don't know what to say Aska, that is awesome. EXACTLY what I was looking for. And I wouldn't have figured it out in a million years without learning JavaScript (and I'm trying to put all of my energies into PHP and OOP atm).

    You have saved me a headache. And coded something perfectly that my site has needed sorting for *months*.
    THANK YOU SO MUCH!

    (I might actually invest some time in learning JavaScript starting with the above code. Elegant solutions like that are exactly why I tried (and failed) to learn it previously)
    HorrorExpress.com - all the latest Horror Movie Reviews and News

  6. #6
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JohnShaft
    WOW.
    I don't know what to say Aska, that is awesome. EXACTLY what I was looking for. And I wouldn't have figured it out in a million years without learning JavaScript (and I'm trying to put all of my energies into PHP and OOP atm).

    You have saved me a headache. And coded something perfectly that my site has needed sorting for *months*.
    THANK YOU SO MUCH!

    (I might actually invest some time in learning JavaScript starting with the above code. Elegant solutions like that are exactly why I tried (and failed) to learn it previously)
    Glad to hear that John. I kind of started out the same way -- I didn't know much JavaScript (just enough to get by) before I learned PHP.

    A couple of good online JS resources I hope you may be interested in:

    http://www.devguru.com/Technologies/...ipt_index.html
    http://www.dynamicdrive.com/

  7. #7
    SitePoint Enthusiast JohnShaft's Avatar
    Join Date
    Oct 2002
    Location
    England
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Aska, I'll check them out for sure.
    [I bought SAMS 'JS in 21 days' book last Christmas, but looking through it I just didn't find anything in it that I wanted to do, for my site. I think it's often best to use websites to find out if you want to invest anymore time and money in learning it. ]

    I sure could use a working knowledge of JS, at minimum.
    So many languages. So little time.
    HorrorExpress.com - all the latest Horror Movie Reviews and News


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
  •