New Vanpool Finder for Forming Vanpools


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <!-- here is the updated code to include the Forming sub-cats -->
  2. <script>
  3. $(document).ready(function() {
  4. var val = $('#blogcategory').attr('value');
  5. $("#vanpoolResults").empty("");
  6. $("#vanpoolResults").fadeOut("fast");
  7.  
  8. $('#blogcategory').change( function() {
  9.  
  10. var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu"
  11. $("#destination_point").fadeOut("slow");
  12. $("#departure_point").fadeOut("fast").empty("");
  13. $("#vanpoolResults").fadeOut("fast").empty("");
  14.  
  15. if ( (chosenoption.value == '142' || chosenoption.value == '159') ) {
  16.  
  17. $("#vanpoolResults").empty("");
  18. var val = $('#blogcategory').attr('value');
  19.  
  20. $.getJSON('./js/comboboxes.php?q=' + val, function(json){
  21.  
  22. $("#destination_point").html("<option value='' selected='selected'>&rarr; Choose your Origin &larr;</option>");
  23. $("#departure_point").fadeOut("fast"); $("#vanpoolResults").fadeOut("fast");
  24.  
  25. for(var i=0; i < json.length; i++){
  26. $("#destination_point").append("<option value='" + json[i].cat_id + "'>" + json[i].cat_name + "</option>"); }
  27.  
  28. $("#destination_point").fadeIn("slow");
  29.  
  30. });// end for loop
  31.  
  32. $('#destination_point').change( function() {
  33. $("#vanpoolResults").fadeOut("fast").empty("");
  34.  
  35. var val2 = $('#destination_point').attr('value');
  36. $.getJSON('./js/new_boxes.php?q=' + val2, function(json2){
  37.  
  38. 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???
  39. $("#vanpoolResults").empty("");
  40. $("#vanpoolResults").append(json2[i].field_id_5).fadeIn("fast"); }
  41.  
  42. }); }); } // end of if
  43.  
  44. // This is the default for all single-destination selection vanpools
  45. else { $.getJSON('./js/new_boxes.php?q=' + chosenoption.value, function(json){
  46. $("#filtersidebar").html("<option>&rarr; Your Available Pools &larr;</option>");
  47. for(var i=0; i < json.length; i++){ $("#vanpoolResults").append(json[i].field_id_5); } $("#vanpoolResults").fadeIn("fast"); }); $("#vanpoolResults").fadeIn("fast");
  48. } });
  49. }); // end something or other, do backflips if this is working and praise Odin
  50.  
  51.  
  52. </script>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.