问题
I am using the select option to select the category from the dropdown list.
when I select the category and submit it..the page is refreshing and the category is reset to default value.
I need to display the selected category after refreshng the page also.
may anyone help me to do this one?
回答1:
<form name="frm" action="" method="post">
<select name="dp" >
<option>Select</option>
<option <?php if (isset($_POST['dp']) && ($_POST['dp']== 'Option 1')) echo " selected='selected'";?> value="Option 1">Option 1</option>
<option <?php if (isset($_POST['dp']) && ($_POST['dp']== 'Option 2')) echo " selected='selected'";?> value="Option 2">Option 2</option>
<option <?php if (isset($_POST['dp']) && ($_POST['dp']== 'Option 3')) echo " selected='selected'";?> value="Option 3">Option 3</option>
</select>
<input type="submit" name="submit" id="submit" value="Submit"/>
</form>
回答2:
try to used $_SESSION
to save the submitted value of option and try again Manu's script just change $_POST
来源:https://stackoverflow.com/questions/17802023/select-options-reset-to-default-value-after-refreshing-the-page