deadsix
deadsix

Reputation: 375

How to filter jQuery Mobile select form dynamically

I'm trying to filter a select list by using another select list. The problem is that I cannot reload the list after its been filtered. So if a user makes a accidentally makes a wrong selection on the first list, no options will be left on the second list. You can see my code below thanks.

        $('#selectCftDialog').change(function() {
            //alert('Handler for .select() called.');
            var tempCftID;
            tempCftID = $("#selectCftDialog").val();
            //alert("The tempCraftID is: CftID-" + tempCraftID)
            $('#selectSpDialog option').not('#CftID-' + tempCftID).remove();    
                    });

Upvotes: 0

Views: 222

Answers (1)

PSL
PSL

Reputation: 123739

What you can do is to save the options as data on the select element itself startup.

$('#selectSpDialog').data('options', $('#selectSpDialog option')); // Set the jquery data `options` with the initial set of options.

$('#selectCftDialog').change(function () {
    //alert('Handler for .select() called.');
    var tempCftID;
    tempCftID = $("#selectCftDialog").val();
    //alert("The tempCraftID is: CftID-" + tempCraftID)
    $('#selectSpDialog option').not('#CftID-' + tempCftID).remove(); // Ok you can remove now
});

function someEventCalledProabablyReset()
{
    var select = $('#selectSpDialog');
    select.html(select.data('options')); //Set back all the saved options.
}

Fiddle

Upvotes: 2

Related Questions