select options reset to default value after refreshing the page

旧街凉风 提交于 2019-12-11 23:06:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!