retaining selected dropdown option on postback

前端 未结 2 1633
一整个雨季
一整个雨季 2020-12-12 04:21

How do I retain whatever was selected from the dropdown even after page refresh so user knows what he/she selected using jquery? or javascript?


                        
    
提交评论

  • 2020-12-12 05:11
    <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>
    
    0 讨论(0)
  • 提交回复
    热议问题