tags:

views:

50

answers:

1

I want to set a dropdown box to what every has been passed through a querystring using jquery.

How do I add the selected attribute to a option that the "TEXT" value = param from the query string.

 $(document).ready(function() {
        var cat = $.jqURL.get('category');
        if (cat != null) {
            cat = $.URLDecode(cat);
            var $dd = $('#cbCategory');
            var $options = $('option', $dd);
            $options.each(function() {
                if ($(this).text() == cat)
                    $(this).select(); // This is where my problem is
            });
        };
    });
+4  A: 

Replace this:

        var $dd = $('#cbCategory');
        var $options = $('option', $dd);
        $options.each(function() {
            if ($(this).text() == cat)
                $(this).select(); // This is where my problem is
        });

With this:

$('#cbCategory').val(cat);

Calling val() on a select list will automatically select the option with that value, if any.

Paolo Bergantino
This worked out great thank you.
OneSmartGuy