#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    64
    Rep Power
    2

    [Solved] Keep Select Input Option On Page Change


    I understand the basics, but I'm not fluent with JS yet. Is there a function that will keep the option selected displayed in the select input on page changes?

    Code:
    <form action="" method="POST">
    <select name="imgCategory" size=1 onChange="this.form.submit()">
                <option value=""></option>
    			<option value="">All Images</option>
                <option value="Amazing">Amazing</option>
                <option value="Funny Animals">Funny Animals</option>
    			<option value="Funny Cartoon">Funny Cartoon</option>
    			<option value="Funny People">Funny People</option>
                <option value="Gross">Gross Pictures</option>
                <option value="Random">Random</option>
                <option value="Stupid People">Stupid People</option>
             </select>
    </form>
    For example, if I select "Funny People" I would like "Funny People" to be displayed in the select input if the page changes.

    SOLVED: Ended up creating a PHP function containing a switch statement.
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,129
    Rep Power
    4304
    Congratulations on finding a solution. While JavaScript could be used to set a cookie to then read back to set the selected value when the page loads, it's better to use a server-side language as you have done.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo