SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to Get Drop-down Selection to appear after Selection

    I am trying to have a value stay selected after it is chosen in a drop-down select box. I'm using an an onchange command which initiates different sorting queries. I just want the selection to be a part of the selected page.

    For example if someone chooses to display only Earwire earrings, I'd like that choice to be selected after the query runs. Any advice? Thanks.


    Code:
    <FORM NAME="sort" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    <SELECT NAME="earcode" onchange="this.form.submit();">
    <!-- <OPTION VALUE="">Sort by Earring Type</option> -->
    <OPTION VALUE=""></option>
    <OPTION VALUE="ALL">Display all Earrings </option>
    <OPTION VALUE="E">Display only Earwire Earrings</option>
    <OPTION VALUE="P">Display only Post Earrings</option>
    <OPTION VALUE="L">Display only Lever back Earrings</option>
    </SELECT>
    
    <noscript>
    <input type="submit" name="earcode" value="Display Selected Earrings">
    </noscript>

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As you create your options in PHP, check if the option value matches the submitted value. If it does then add selected="selected" to the tag.
    Code:
    <option value="E" selected="selected">Display only Earwire Earrings</option>

  3. #3
    SitePoint Evangelist bals28mjk's Avatar
    Join Date
    Aug 2007
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's because whenever you submit the page for query it refreshes itself. Before you submit you need to store the state of your select box inside a cookie.
    Last edited by bals28mjk; Sep 2, 2007 at 00:03.


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
  •