1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Refresh page after selecting dropdown

Discussion in 'PHP' started by ghjk, Mar 26, 2008.

  1. #1
    I have a dropdown box and what i want to do is refresh the page when i select one of the options, but i need to keep that variable that i chose as it effects my sql statements
    SEMrush
     
    ghjk, Mar 26, 2008 IP
    SEMrush
  2. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #2
    Try this
    
     <select name="abc" [B] onChange="Refresh(this.value)"[/B]>
    
    Code (markup):
    And add this code in <head> section of document.

    
    function Refresh(id){
    location.href="your_page.php?abc=" + id 
    }
    PHP:
    get the value of $id and use it to check selected value in list.
     
    greatlogix, Mar 26, 2008 IP
  3. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <select name="select_name" onchange="this.form.submit();">
    PHP:
    then some <option> tag pairs, that look like this

    <option <?php if ($_POST['select_name'] == 'option_value') print 'selected '; ?> value="option_value">Option Name</option>
    PHP:
     
    matthewrobertbell, Mar 26, 2008 IP
  4. ghjk

    ghjk Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks a lot greatlogix and matthewrobertbell. But the thing is after reloadding the page , I want to keep the value that i have selected . How can i do that? Please help.
     
    ghjk, Mar 26, 2008 IP
  5. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #5
    That's what the second part of my code is for, it checks to see if that <option> was submitted last time and if so sets it to "selected"
     
    matthewrobertbell, Mar 26, 2008 IP
  6. ghjk

    ghjk Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This is what i have done. But it is not working.

     
    ghjk, Mar 26, 2008 IP
  7. ghjk

    ghjk Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Sorry matthewrobertbell earlier i made a mistake. Now my code is working . Thanks a lot.. Here is my code
    php Code:

    <form action="test.php" method="post" name="test" >
    <select name="District" onchange="this.form.submit();">
    <option <?php if ($_POST['District'] == 'G1') print 'selected '; ?> value="G1">G1</option>
    <option <?php if ($_POST['District'] == 'G2') print 'selected '; ?> value="G2">G2</option>
    <option <?php if ($_POST['District'] == 'G3') print 'selected '; ?> value="G3">G3</option>
    <option <?php if ($_POST['District'] == 'G4') print 'selected '; ?> value="G4">G4</option>


    </select> </form>
     
    ghjk, Mar 26, 2008 IP