retain dropdown selection on refresh [duplicate]

こ雲淡風輕ζ 提交于 2019-11-29 15:14:35
jflaflamme

For a clean method you can set a cookie

Take a look at the following question and the replies

jQuery cookies setting select drop down value after page refresh

*But my favorite is to set the selection in the user session using ajax method.

<select id="hospitalDropDown"> 
    <option value="">All Hospitals</option>
    <option value="Dyer">Dyer</option>
    <option value="Carmel">Carmel</option>
</select>
<script type="text/javascript">

$(document).ready(function() {
    $('#hospitalDropDown').val('<?php echo $_GET['hos']; ?>');
    $('#hospitalDropDown').change(function() {
        location.href = 'http://mysite.com/events/Pages/default1.aspx?hos=' + $(this).val();
    });
});
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!