Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. <form id=categorySelection>
  2. <label>
  3. <select>
  4. <option value="" disabled selected>SELECT CAT</option>
  5. <option data-idToShow=test1>Einkaufen & Dienstleistungen</option>
  6. </select>
  7. </label>
  8. <label id=test1 class=displayNone>
  9. <select>
  10. <option value="" disabled selected>PLEASE SELECT</option>
  11. <option data-idToShow=catSelect1>CAT 1</option>
  12. <option>Webseiten</option>
  13. </select>
  14. </label>
  15. <label id=catSelect1 class=displayNone>
  16. <select>
  17. <option value="" disabled selected>PLEASE SELECT</option>
  18. <option data-idToShow=catSelect2>CAT 1</option>
  19. <option>CAT X</option>
  20. <option>CAT Y</option>
  21. </select>
  22. </label>
  23. <label id=catSelect2 class=displayNone>
  24. <select>
  25. <option value="" disabled selected>PLEASE SELECT</option>
  26. <option>CAT a</option>
  27. <option>CAT b</option>
  28. <option>CAT c</option>
  29. <option data-idToShow=catSelect3>CAT D</option>
  30. <option>CAT</option>
  31. <option>CAT</option>
  32. <option data-idToShow=catSelect4>CAT</option>
  33. </select>
  34. </label>
  35. <label id=catSelect4 class=displayNone>
  36. <select>
  37. <option value="" disabled selected>PLEASE SELECT</option>
  38. <option>CAT</option>
  39. <option data-idToShow=catSelect5>CAT</option>
  40. </select>
  41. </label>
  42. <label id=catSelect5 class=displayNone>
  43. <select>
  44. <option value="" disabled selected>PLEASE SELECT</option>
  45. <option>CAT</option>
  46. <option>CAT</option>
  47. <option>CAT</option>
  48. <option>CAT</option>
  49. <option>CAT</option>
  50. <option>CAT</option>
  51. </select>
  52. </label>
  53. <label id=catSelectXXX class=displayNone>
  54. <select>
  55. <option value="" disabled selected>PLEASE SELECT</option>
  56. <option>CAT</option>
  57. <option>CAT</option>
  58. <option>CAT</option>
  59. </select>
  60. </label>
  61. <label id=catSelectXXX class=displayNone>
  62. <select>
  63. <option value="" disabled selected>PLEASE SELECT</option>
  64. <option>CAT</option>
  65. <option>CAT</option>
  66. <option>CAT</option>
  67. </select>
  68. </label>
  69. <label id=catSelectXXX class=displayNone>
  70. <select>
  71. <option value="" disabled selected>Bitte wähle die Art des Kurses</option>
  72. <option>CAT</option>
  73. <option>CAT</option>
  74. <option>CAT</option>
  75. </select>
  76. </label>
  77. </form>
  78. <script>
  79.  
  80. (function categorySelection() {
  81.  
  82. var f = document.getElementById( "categorySelection" );
  83.  
  84. f.onchange = function() {
  85.  
  86. hideAllVisibleSubElements();
  87. var els = document.querySelectorAll('form#categorySelection > label > select > option');
  88. for(var i = 0; i < els.length; i++) {
  89. var e = els[i];
  90. var idToShow = e.getAttribute('data-idToShow');
  91.  
  92. if( e.selected === true && idToShow !== null ) {
  93. console.log("HTML: " + e.innerHTML + " selected: " + e.selected + " idToShow: " + idToShow);
  94. showId(idToShow);
  95. }
  96. }
  97. }
  98. }
  99.  
  100. function hideAllVisibleSubElements( ) {
  101.  
  102. var els = document.querySelectorAll('#categorySelection > label:nth-of-type(1n+2) > select');
  103. /*
  104. for(var i = 0; i < els.length; i++) {
  105. var e = els[i];
  106. e.selectedIndex = 0;
  107. }
  108. */
  109. var els = document.querySelectorAll('#categorySelection > label:nth-of-type(1n+2)');
  110.  
  111. for(var i = 0; i < els.length; i++) {
  112. var e = els[i];
  113. if( !e.hasClass('displayNone') ){
  114. e.addClass('displayNone');
  115. }
  116. }
  117. }
  118.  
  119. function showId( id ) {
  120. var e = document.getElementById( id );
  121. if( e.hasClass('displayNone') ){
  122. e.removeClass('displayNone');
  123. }
  124. }
  125.  
  126. categorySelection();
  127. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement