javascript - How to keep selected value after submit form - JQuery -


i have form:

<form id="new_user" class="simple_form new_user" method="post" accept-charset="utf-8" action="/admin/stats" novalidate="novalidate">     <div class="col-lg-4">         <h2>stats by:</h2>         <div class="col-md-10 col-sm-10">             <div class="form-group country optional user_country">                 <select id="user_country" class="country optional wabi-form-control select form-control" name="user[country]">             </div>         </div>         <div class="col-md-10 col-sm-10">             <input class="btn btn-wabi btn-block" type="submit" value="show stats" name="commit">         </div>     </div> </form>' 

ho keep selected value user_country after show stats button click?

with php, put select/input:

value="<?php echo isset($_post['user_country']) ? $_post['user_country'] : '' ?>" 

javascript:

document.getelementbyid("user_country").value = localstorage.getitem("user_country");  function saveinput() {     var country = document.getelementbyid("user_country").value;     if (country == "") {         alert("please select country first!");         return false;     }      localstorage.setitem("user_country", country);     alert("your country has been saved!");      location.reload();     return false;     //return true; } 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -