Question

I am trying to change select boxes in order based on what is previously selected. I have it working for the first one to change but not the third. If someone can help me make third one work that would be great.

http://jsfiddle.net/Ze5AA/21/

Here is the js I am using:

$("#CAT_Custom_496270").change(function() { 
    if($(this).data('options') == undefined){
        $(this).data('options',$('#CAT_Custom_495029 option').clone());
    } 

    var id = $(this).val();
    var options = $(this).data('options').filter('[value*=' + id + ']');
    $('#CAT_Custom_495029').html(options);
});

$("#CAT_Custom_495029").change(function() { 
    if($(this).data('options') == undefined){
        $(this).data('options',$('#CAT_Custom_495038 option').clone());
    } 
    var id = $(this).val();
    var options = $(this).data('options').filter('[value*=' + id + ']');
    $('#CAT_Custom_495038').html(options);
});
Était-ce utile?

La solution

Wrap your value attribute filter's value in quotes, since there is a space in the values.

var options = $(this).data('options').filter('[value*="' + id + '"]');

Fiddle

Autres conseils

your values aren't consistant for what you are checking for because of the spaces.

you can wrap it in quotes, though I would only just get the value you need (the first 3 characters) to keep it cleaner

you need to split the check, I would add a delimiter to make it easy.

 //html example from menu 2
    <option value="CSD: 0-45">0-45</option>
        <option value="CSD: 46-50">46-50</option> //note the colon after CSD

 //html from menu 3

<option value="CSD: $25.40/month /20 Year Pay">$25.40/month /20 Year Pay</option>

<option value="CSD: $26.05/month /20 Year Pay">$26.05/month /20 Year Pay</option>

<option value="CSD: 51 $27.50/month /20 Year Pay">$27.50/month /20 Year Pay</option> //note the color again


 //the java

   var id = $(this).val().split(":"); //makes a 2 value array split at the colon
   var options = $(this).data('options').filter('[value*=' + id[0] + ']'); //we want the first array value (before the colon)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top