Cara menyimpan nilai pada componen bootstrap, ketika browser di refresh nilai tetep sama

 DF - Tutorial menyimpan nilai dropdown tidak berubah setelah dipilih. Kondisi browser di refresh tetep nilai tidak berubah. Yaitu dengan  menyimpan ke localStorage.


<script>

  // Function to save the selected dropdown value to localStorage

  function saveDropdownValue() {

    var selectedValue = document.getElementById('id_dispenser').value;

    localStorage.setItem('dropdownValue', selectedValue);

  }


  // Function to load the saved dropdown value from localStorage

  function loadDropdownValue() {

    var savedValue = localStorage.getItem('dropdownValue');

    if (savedValue) {

      document.getElementById('id_dispenser').value = savedValue;

    }

  }


  // Load the saved value when the page is loaded

  document.addEventListener('DOMContentLoaded', loadDropdownValue);


  // Save the value whenever the dropdown changes

  document.getElementById('id_dispenser').addEventListener('change', saveDropdownValue);

</script>

NextGen Digital... Welcome to WhatsApp chat
Howdy! How can we help you today?
Type here...