javascript - Related dropdown menu issue -


i'm polishing bit of jquery wrote works on 2 dropdown boxes. basically, when first dropdown changed, filters second dropdown show applicable choices. if first choice (value: "none|") chosen in first dropdown, shows no choices in second

it works great, of time. here's issue: if select first choice in first dropdown, second dropdown clears out. if choose option in first dropdown, second stays empty when shouldn't.

i'd appreciate if can me figure out. can find dropdown boxes here: http://goinspire.com/jwrp-hotel-registration/.

ps: if makes difference (but think doesn't), it's wordpress site , form generated gravityforms.

ps: here's code:

tripfilter = function () {          var tripclass = '.hotel-trip select',             hotelclass  = '.hotel-name select',             unusedclass = '.unused-options select';         jquery(tripclass).change(function(){             //testfunc();              var tripselect = jquery(tripclass),                 trip = tripselect.val(),                 hotelselect = tripselect.parents('form').find(hotelclass);             if (trip === "none|"){                 jquery(hotelclass+" > option").each(function() {                     jquery(this).clone().appendto(unusedclass);                     jquery(this).remove();                 });              } else {                 tripnum =  trip.match(/jwrp (\d*)/)[1];                  //var hotelchoices = [];                 jquery(unusedclass+" > option").each(function() {                         jquery(this).clone().appendto(hotelclass);                         jquery(this).remove();                 });                 jquery(hotelclass+" > option").each(function() {                     hotelmatch = jquery(this).val().match(/(\d*) /);                     //console.log(hotelmatch);                     if (hotelmatch === null || hotelmatch[1] != tripnum){                         jquery(this).clone().appendto(unusedclass);                         jquery(this).remove();                         //console.log("not match!");                     };                 });              }      }); };     jquery(document).ready(function () {     tripfilter(); }); jquery(document).bind('gform_post_render', function(event, form_id){     if(form_id == 38) {         tripfilter();     } }); 

if have understood properly, first dropdowm guides second. so, think might add listener on "change" event of first dropdown, perform function every time value of first input goes through change.

try way:

$(document).ready(function(){     $('#38').bind('change', tripfilter) }); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -