Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js check if field in database is true or false

let taskDone = document.querySelectorAll('.taskDone'); //get all the chechbox with same class .taskDone
taskDone.forEach(function(btn) { //use normal function
  btn.addEventListener('change', function() {
    let id = $(this).data('id') //get the data id of checkbox
    if ($(this).is(':checked')) { //check if the clicked checkbox is checked or not
      console.log(id + ' is Checked - Updating neDB') //console.log
      $.ajax({
        url: 'http://localhost:3000/done/' + id,
        type: 'PUT',
        data: 'isDone'
      }).done(function(data) {
        console.log(data)
      })
    } else {
      console.log("Not Checked")
    }
  })
})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #check #field #database #true #false
ADD COMMENT
Topic
Name
1+1 =