Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript I’ll give you a cookie if you can tell me what’s wrong

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #41398
    KMarimon1
    Participant

    I have two selects on my page

    I use some jquery for client side filtering

    $(document).ready(function(){
    var $cat = $(‘select[name=category]’),
    $items = $(‘select[name=items]’);

    $cat.change(function(){
    var $this = $(this).find(‘:selected’),
    rel = $this.attr(‘rel’),
    $set = $items.find(‘option.’ + rel);

    if ($set.size() < 0) {
    $items.hide();
    return;
    }

    $items.show().find(‘option’).hide();

    $set.show().first().prop(‘selected’, true);
    });
    });‚Äč

    I’m using the latest version of jquery, dunno why my selects are behaving the way that they do.

    I got the idea from this jsfiddle

    http://jsfiddle.net/userdude/bY5LF/

    here’s my jsfiddle

    http://jsfiddle.net/kmarimon1/P89aT/

    I’ll give you a cookie for enlightening me!

    Thanks!

    #117795
    KMarimon1
    Participant

    it’s filtering for you? Are you sure?

    #117808
    Senff
    Participant

    Working fine for me too: http://jsfiddle.net/senff/zmzHw/

    (though I wouldn’t use just numbers as class names)

    #117802
    chrisburton
    Participant

    What browser are you using @KMarimon1?

    #117813
    David_Leitch
    Participant

    It’s not working correctly for me; it just jumps to the start of the relevant part of the drop down list, but does not filter out the irrelevant cities. I’m using Safari 6.0. Also does not work on Chrome 23.0.1271.101. Does work on Firefox 13.0.1 though

    Unfortunately, I don’t have much skill in Javascript, so I’ll leave it to those more experienced, but thought you’d want to know what browsers it’s functioning in :)

    #117817
    David_Leitch
    Participant

    Did a bit of research and found another solution for you that seems to be working in all of the browsers I’m using. I can’t take _any_ of the credit, but I will take _all_ of the cookies :D

    Solution found [here](http://stackoverflow.com/questions/7697936/jquery-show-hide-options-from-one-select-drop-down-when-option-on-other-selecthttp://stackoverflow.com/questions/7697936/jquery-show-hide-options-from-one-select-drop-down-when-option-on-other-select&#8221;).

    Codepen example with your data [here](http://codepen.io/David_Leitch/pen/ciAEJhttp://codepen.io/David_Leitch/pen/ciAEJ&#8221;)

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.