Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
How to Keep checkbox previous state after refresh
<div class="col-sm-12 form-group mt-15">
  <label class="active">Blood Group</label>
  <span style="float: right;">
     <input type="checkbox" id="emp_blood_group"  name="colorCheckbox" value="0" > 
  </span>
</div>

<tr>
    <td class="text-right v-middle blood_group hide "><?php echo $employee['blood_group']; ?></td>
</tr>

<script type="text/javascript">
    $(document).ready(function () {
        if (localStorage.getItem("emp_blood_group") !== null)
            $("#emp_blood_group").prop("checked", localStorage.getItem("emp_blood_group") == ("true" || "false"));
            //localStorage.removeItem("emp_blood_group"); //if you want the data to persist only for the first reload
    });

    $("#emp_blood_group").click(function () {
        var blood_group = $("#emp_blood_group").prop("checked");
        localStorage.setItem("emp_blood_group", blood_group.toString());
        blood_group == true ? $(".blood_group").removeClass("hide") : $(".blood_group").addClass("hide");
    });

    $( window ).on( "load", function() {
        if ($('#emp_blood_group').is(":checked"))
        {
            emp_blood_group=$('#emp_blood_group').val();
            window.alert(emp_blood_group)
        }else{
            window.alert('sfsf')
        }
    });
</script>

Here i have using checkbox for added dynamically table row and after did some filter operation on table after filter page is refreshing checkbox becomes previous state which i have clicked like Shows tick on checkbox But in load function if condition not working . its goes to else.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!