The issue I’m having is that I need to refresh a page after iterate a list of checkbox and deleting the selection. The code I have only delete the first selection and location.reload(); is call so the rest of the selection is not deleted. Please tell me
what and I doing wrong?
function deleteLists() { var deldiv = document.getElementById("deleteList").getElementsByTagName("input"); for (var i=0; i < deldiv.length; i++){ if (deldiv[i].type.toUpperCase() =='CHECKBOX') { if (deldiv[i].checked){ console.log('Deleting: ' + deldiv[i].id); deleteCustomerByID(deldiv[i].id); } } } //Refresh Page location.reload(); } function deleteCustomerByID(id) { var transaction = db.transaction(["customerTable99"],"readwrite"); var objectStore = transaction.objectStore('customerTable99'); var request = objectStore.delete(Number(id)); request.onerror = function(e){ console.log('Error Deleting'); } request.onsuccess = function(e){ console.log('Delete compelete'); } }
Hi ducewild,
For your issues is related with transaction.objectStore which is out of our support scope ,please post your issue to the link below for a professional solution.
https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore
Best regards,
Aswecan
Hi ducewild,
First, please make sure that you have delete the element before you call location.reload function to refresh your page.
Second, i guess the issue is that when you reload your page, it will load all the checkboxes for you,for i am not quite sure how did you delete your selection.
If you just delete in your page,but not in your database,and when you refresh the page,it will load all the checkbox from your database for you.
Last ,i suggest that you can press F12 to debug your page ,see if it has any logical issue.
Best Regards,
Kevin Shen.
Thank for the reply Kevin. When in debug I walk thru each step and every checkbox that is selected get delete from database and page reload fine. When I’m not in debug location.reload(); is call before all the selection is deleted from the database. Usually
only the first selection is deleted and the page is reload.
Hi ducewild,
Based on my understanding ,if you didn’t set a debug, there will just only one record deleted.
If you do ,it will delete all the checkboxes selection.
I think there maybe some network delay when you reload your page.
And I suggest that you can add a function to recall the database and set the value to your checkbox after you delete the checkbox, refresh your page.
Best Regards,
Kevin Shen.