Skip to main content
deleted 4 characters in body
Source Link
Nicola Peluchetti
  • 77k
  • 32
  • 150
  • 197

You could use nextUntil() and do like this:

var allOptions = $("#input_13 option"); jQuery('#input_1_34').bind('change', function()  {   //get selected value from drop down   var selectedValue = jQuery("#input_1_34").val();  //hide everything but bases for the selected state   //jQuery$("#input_13 option[value=" + selectedValue + "]"'#input_13').nexthtml('').removeappend(allOptions);   selectedOptions = $("#input_13 option[value=" + selectedValue + "]").nextUntil('.level-0').andSelf();;;   $('#input_13').html('').append(selectedOptions);  }); 

EDIT- i changed the answer to allow the user to choose more options

Look at the fiddle here: http://jsfiddle.net/QGCh4/1/http://jsfiddle.net/QGCh4/2/

You could use nextUntil() and do like this:

 jQuery('#input_1_34').bind('change', function()  {   //get selected value from drop down   var selectedValue = jQuery("#input_1_34").val();  //hide everything but bases for the selected state   //jQuery("#input_13 option[value=" + selectedValue + "]").next().remove();   selectedOptions = $("#input_13 option[value=" + selectedValue + "]").nextUntil('.level-0').andSelf();;   $('#input_13').html('').append(selectedOptions);  }); 

Look at the fiddle here: http://jsfiddle.net/QGCh4/1/

You could use nextUntil() and do like this:

var allOptions = $("#input_13 option"); jQuery('#input_1_34').bind('change', function() { //get selected value from drop down var selectedValue = jQuery("#input_1_34").val(); $('#input_13').html('').append(allOptions); selectedOptions = $("#input_13 option[value=" + selectedValue + "]").nextUntil('.level-0').andSelf(); $('#input_13').html('').append(selectedOptions); }); 

EDIT- i changed the answer to allow the user to choose more options

Look at the fiddle here: http://jsfiddle.net/QGCh4/2/

Post Undeleted by Nicola Peluchetti
added 57 characters in body
Source Link
Nicola Peluchetti
  • 77k
  • 32
  • 150
  • 197

You could use nextAllnextUntil() and do like this:

 jQuery('#input_1_34').bind('change', function() { //get selected value from drop down var selectedValue = jQuery("#input_1_34").val(); //hide everything but bases for the selected state //jQuery("#input_13 option[value=" + selectedValue + "]").next().remove(); selectedOptionselectedOptions = jQuery$("#input_13 option[value=" + selectedValue + "]");.nextUntil('.level-0').andSelf();;  selectedOption $('#input_13').nextAllhtml('').removeappend(selectedOptions); }); 

Look at the fiddle here: http://jsfiddle.net/QGCh4/http://jsfiddle.net/QGCh4/1/

You could use nextAll() like this:

 jQuery('#input_1_34').bind('change', function() { //get selected value from drop down var selectedValue = jQuery("#input_1_34").val(); //hide everything but bases for the selected state //jQuery("#input_13 option[value=" + selectedValue + "]").next().remove(); selectedOption = jQuery("#input_13 option[value=" + selectedValue + "]"); selectedOption.nextAll().remove(); }); 

Look at the fiddle here: http://jsfiddle.net/QGCh4/

You could use nextUntil() and do like this:

 jQuery('#input_1_34').bind('change', function() { //get selected value from drop down var selectedValue = jQuery("#input_1_34").val(); //hide everything but bases for the selected state //jQuery("#input_13 option[value=" + selectedValue + "]").next().remove(); selectedOptions = $("#input_13 option[value=" + selectedValue + "]").nextUntil('.level-0').andSelf();;   $('#input_13').html('').append(selectedOptions); }); 

Look at the fiddle here: http://jsfiddle.net/QGCh4/1/

Post Deleted by Nicola Peluchetti
Source Link
Nicola Peluchetti
  • 77k
  • 32
  • 150
  • 197

You could use nextAll() like this:

 jQuery('#input_1_34').bind('change', function() { //get selected value from drop down var selectedValue = jQuery("#input_1_34").val(); //hide everything but bases for the selected state //jQuery("#input_13 option[value=" + selectedValue + "]").next().remove(); selectedOption = jQuery("#input_13 option[value=" + selectedValue + "]"); selectedOption.nextAll().remove(); }); 

Look at the fiddle here: http://jsfiddle.net/QGCh4/