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

    Join Date
    Dec 2012
    Rep Power

    [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?

    <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>
    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
    USA (verifiably)
    Rep Power
    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.

    Learn CSS. | PHP includes | HTML Validator | CSS validator

    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