1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>Document</title>
  9. <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  10. </head>
  11. <body dir="rtl">
  12. <div id="colleges">
  13. <input type="checkbox" id="college_all">همه دانشکده ها
  14. <?php
  15. /**
  16. * Created by PhpStorm.
  17. * User: mahdi
  18. * Date: 1/6/19
  19. * Time: 8:03 AM
  20. */
  21. include_once('college.php');
  22. ?>
  23. </div>
  24. <div id="groups">
  25. <input type="checkbox" disabled id="group_all">همه گروه ها
  26. </div>
  27. <div id="majors">
  28. <input type="checkbox" disabled id="major_all">همه رشته ها
  29. </div>
  30. <script>
  31. $("#college_all").click(function () {
  32. var checked = this.checked;
  33. $(".college").each(function(){
  34. if (this.checked != checked) $(this).trigger('click');
  35. })
  36. })
  37. $("#group_all").click(function () {
  38. var checked = this.checked;
  39. $(".group").each(function(){
  40. if (this.checked != checked) $(this).trigger('click');
  41. })
  42. })
  43. $("#major_all").click(function () {
  44. var checked = this.checked;
  45. $(".major").each(function(){
  46. if (this.checked != checked) $(this).trigger('click');
  47. })
  48. })
  49. $(".college").change(function () {
  50. if (this.checked) {
  51. $("#group_all").removeAttr("disabled");
  52. val = $(this).val();
  53. if(val){
  54. $.ajax({
  55. type: "GET",
  56. url: 'getgroup.php?collegeid=' + val,
  57. success: function (data) {
  58. $("#groups").append(data);
  59. $(".group").change(function () {
  60. if (this.checked) {
  61. $("#major_all").removeAttr("disabled");
  62. val1 = $(this).val();
  63. if(val1){
  64. $.ajax({
  65. type: "GET",
  66. url: 'getmajor.php?groupid=' + val1,
  67. success: function (data) {
  68. $("#majors").append(data);
  69. }
  70. })
  71. }
  72. } else {
  73. v = $(this).val();
  74. gclass = ".groupid" + v;
  75. // alert(gclass);
  76. $(gclass).remove();
  77. }
  78. })
  79. }
  80. })
  81. }
  82. } else {
  83. v1 = $(this).val();
  84. cclass = ".collegeid" + v1;
  85. // alert()
  86. $(cclass).remove();
  87. }
  88. })
  89. </script>
  90. </body>
  91. </html>

ajax.php