Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form id=categorySelection>
- <label>
- <select>
- <option value="" disabled selected>SELECT CAT</option>
- <option data-idToShow=test1>Einkaufen & Dienstleistungen</option>
- </select>
- </label>
- <label id=test1 class=displayNone>
- <select>
- <option value="" disabled selected>PLEASE SELECT</option>
- <option data-idToShow=catSelect1>CAT 1</option>
- <option>Webseiten</option>
- </select>
- </label>
- <label id=catSelect1 class=displayNone>
- <select>
- <option value="" disabled selected>PLEASE SELECT</option>
- <option data-idToShow=catSelect2>CAT 1</option>
- <option>CAT X</option>
- <option>CAT Y</option>
- </select>
- </label>
- <label id=catSelect2 class=displayNone>
- <select>
- <option value="" disabled selected>PLEASE SELECT</option>
- <option>CAT a</option>
- <option>CAT b</option>
- <option>CAT c</option>
- <option data-idToShow=catSelect3>CAT D</option>
- <option>CAT</option>
- <option>CAT</option>
- <option data-idToShow=catSelect4>CAT</option>
- </select>
- </label>
- <label id=catSelect4 class=displayNone>
- <select>
- <option value="" disabled selected>PLEASE SELECT</option>
- <option>CAT</option>
- <option data-idToShow=catSelect5>CAT</option>
- </select>
- </label>
- <label id=catSelect5 class=displayNone>
- <select>
- <option value="" disabled selected>PLEASE SELECT</option>
- <option>CAT</option>
- <option>CAT</option>
- <option>CAT</option>
- <option>CAT</option>
- <option>CAT</option>
- <option>CAT</option>
- </select>
- </label>
- <label id=catSelectXXX class=displayNone>
- <select>
- <option value="" disabled selected>PLEASE SELECT</option>
- <option>CAT</option>
- <option>CAT</option>
- <option>CAT</option>
- </select>
- </label>
- <label id=catSelectXXX class=displayNone>
- <select>
- <option value="" disabled selected>PLEASE SELECT</option>
- <option>CAT</option>
- <option>CAT</option>
- <option>CAT</option>
- </select>
- </label>
- <label id=catSelectXXX class=displayNone>
- <select>
- <option value="" disabled selected>Bitte wähle die Art des Kurses</option>
- <option>CAT</option>
- <option>CAT</option>
- <option>CAT</option>
- </select>
- </label>
- </form>
- <script>
- (function categorySelection() {
- var f = document.getElementById( "categorySelection" );
- f.onchange = function() {
- hideAllVisibleSubElements();
- var els = document.querySelectorAll('form#categorySelection > label > select > option');
- for(var i = 0; i < els.length; i++) {
- var e = els[i];
- var idToShow = e.getAttribute('data-idToShow');
- if( e.selected === true && idToShow !== null ) {
- console.log("HTML: " + e.innerHTML + " selected: " + e.selected + " idToShow: " + idToShow);
- showId(idToShow);
- }
- }
- }
- }
- function hideAllVisibleSubElements( ) {
- var els = document.querySelectorAll('#categorySelection > label:nth-of-type(1n+2) > select');
- /*
- for(var i = 0; i < els.length; i++) {
- var e = els[i];
- e.selectedIndex = 0;
- }
- */
- var els = document.querySelectorAll('#categorySelection > label:nth-of-type(1n+2)');
- for(var i = 0; i < els.length; i++) {
- var e = els[i];
- if( !e.hasClass('displayNone') ){
- e.addClass('displayNone');
- }
- }
- }
- function showId( id ) {
- var e = document.getElementById( id );
- if( e.hasClass('displayNone') ){
- e.removeClass('displayNone');
- }
- }
- categorySelection();
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement