Attie

Attie

  • NA
  • 95
  • 2.3k

CHeckbox to update the database

Mar 9 2018 6:38 AM
Good Day
 
Yesterday I tried to ask a question but I think I failed to explained what is it that I clearly searching for. I want an uncheck/check all checkbox, that when clicked all the values in the selected checkboxes be stored into the database, when unchecked be removed. Currently I have the checkbox that i working only to check and uncheck but not doing anything to the database (SQL Server).
  1. <script type="text/javascript">  
  2. function toggleChecked(status)  
  3. {  
  4. $("#checkboxes input").each(function ()  
  5. {  
  6. $(this).prop("checked", status);  
  7. });  
  8. }  
  9. $(document).ready(function ()  
  10. {  
  11. // Changing state of CheckAll checkbox  
  12. $("#checkboxes").click(function ()  
  13. {  
  14. if ($("#checkboxes").length == $("#checkboxes input:checked").length)  
  15. {  
  16. $("#checkall").prop("checked"true);  
  17. }  
  18. else  
  19. {  
  20. $("#checkall").removeAttr("checked");  
  21. }  
  22. });  
  23. $("#checkall").click(function ()  
  24. {  
  25. var status = $("#checkall").prop('checked');  
  26. toggleChecked(status);  
  27. });  
  28. });  
  29. </script>  
  30. <b>  
  31. <label>  
  32. Check/Uncheck All  
  33. </label>  
  34. <label class="switch">  
  35. <input type="checkbox" id="checkall">  
  36. <span class="slider round">  
  37. </span>  
  38. </label>  
  39. </b>  
  40. <br />  
  41. <div id="checkboxes" style="height: 500px;position:relative;border:1px solid darkgray">  
  42. <div id="div2" style="max-height:100%;overflow:auto;">  
  43. <div id="suburbsDiv"></div>  
  44. </div>  
  45. </div>

Answers (8)