tags:

views:

19

answers:

2

Hello,

I have a list of options dependent on what is selected in the first option. How can I make it so that after they select location the second options only displays options avaliable to that location?

Right now I have a bunch of

<option class=2 DISABLED>Blah</option>

jQuery Code

$(document).ready(function() {
  $('#location').change(function() {
    $(.$(this).val()).removeAttr('disabled');
  });
});

The value of the location option is = to the class of the second. But it doesn't seem to work?

+2  A: 

The selector needs to be in quotes.

$('.' + $(this).val()).removeAttr('disabled');
a.feng
And if you also specifies the context there will be much better performance (selecting by only classname in the whole DOM isn't that fast):$("." + $(this).val(), $("#theSelect")).removeAttr("disabled");
Peter Forss
A: 

For sanitys sake I would change around that selector to something along the lines of:

$(document).ready(function() {
  $('#location').change(function() {
    var curLoc = $(this).val();
    $('.' + curLoc).removeAttr('disabled');
  });
}); 

Edit- Per Jon Cram <option disabled> is acceptable in non-xhtml doctypes.

HurnsMobile
<option disabled="disabled"> is valid only if using an XHTML doctype. <option disabled> is perfectly valid for HTML.
Jon Cram
@Jon - I stand corrected. Thanks for the input Jon!
HurnsMobile