0

I am trying to change the value of an input field after the user clicks on a button. It changes the value to false, but it doesn't seem like it actually "refreshes" when calling the .val() again.

Here's a JS Fiddle example: https://jsfiddle.net/hguom7x8/

As you can see, the alert shows that the value is true, and then it shows that it's false, but then it doesn't show that it's true any time after that anymore.

$("#filter_assessment_list").click(function(){
  upcoming_assessments = $("#upcoming_assessments").val()
  alert(upcoming_assessments)
  if(upcoming_assessments){
    $("#upcoming_assessments").val(false)
  }
  else{
    $("#upcoming_assessments").val(true)
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="btn btn-sm btn-primary text-white" id="filter_assessment_list" href="javascript:;">
        Show only upcoming assessments
</a>

<input type="hidden" name="upcoming_assessments" id="upcoming_assessments" value="true">
Dominik
  • 6,078
  • 8
  • 37
  • 61
LewlSauce
  • 5,326
  • 8
  • 44
  • 91

0 Answers0