/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!-- here is the updated code to include the Forming sub-cats --> <script> $(document).ready(function() { var val = $('#blogcategory').attr('value'); $("#vanpoolResults").empty(""); $("#vanpoolResults").fadeOut("fast"); $('#blogcategory').change( function() { var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu" $("#destination_point").fadeOut("slow"); $("#departure_point").fadeOut("fast").empty(""); $("#vanpoolResults").fadeOut("fast").empty(""); if ( (chosenoption.value == '142' || chosenoption.value == '159') ) { $("#vanpoolResults").empty(""); var val = $('#blogcategory').attr('value'); $.getJSON('./js/comboboxes.php?q=' + val, function(json){ $("#destination_point").html("<option value='' selected='selected'>→ Choose your Origin ←</option>"); $("#departure_point").fadeOut("fast"); $("#vanpoolResults").fadeOut("fast"); for(var i=0; i < json.length; i++){ $("#destination_point").append("<option value='" + json[i].cat_id + "'>" + json[i].cat_name + "</option>"); } $("#destination_point").fadeIn("slow"); });// end for loop $('#destination_point').change( function() { $("#vanpoolResults").fadeOut("fast").empty(""); var val2 = $('#destination_point').attr('value'); $.getJSON('./js/new_boxes.php?q=' + val2, function(json2){ for(var i=0; i < 1; i++){ // This for loop is executing multiple times depending on the number of times you have chosen an option that has a secondary menu. Second time you've chosen one - it executes this twice. Third time - executes 3 times. etc. on and on. WHYYYYY??? $("#vanpoolResults").empty(""); $("#vanpoolResults").append(json2[i].field_id_5).fadeIn("fast"); } }); }); } // end of if // This is the default for all single-destination selection vanpools else { $.getJSON('./js/new_boxes.php?q=' + chosenoption.value, function(json){ $("#filtersidebar").html("<option>→ Your Available Pools ←</option>"); for(var i=0; i < json.length; i++){ $("#vanpoolResults").append(json[i].field_id_5); } $("#vanpoolResults").fadeIn("fast"); }); $("#vanpoolResults").fadeIn("fast"); } }); }); // end something or other, do backflips if this is working and praise Odin </script>