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
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.
<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:
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.
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"
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>