Home › Forums › JavaScript › I’ll give you a cookie if you can tell me what’s wrong
- This topic is empty.
-
AuthorPosts
-
December 17, 2012 at 11:07 am #41398KMarimon1Participant
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!
December 17, 2012 at 11:43 am #117795KMarimon1Participantit’s filtering for you? Are you sure?
December 17, 2012 at 1:22 pm #117808SenffParticipantWorking fine for me too: http://jsfiddle.net/senff/zmzHw/
(though I wouldn’t use just numbers as class names)
December 17, 2012 at 1:42 pm #117802chrisburtonParticipantWhat browser are you using @KMarimon1?
December 17, 2012 at 2:53 pm #117813David_LeitchParticipantIt’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 :)
December 17, 2012 at 4:21 pm #117817David_LeitchParticipantDid 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-select “http://stackoverflow.com/questions/7697936/jquery-show-hide-options-from-one-select-drop-down-when-option-on-other-select”).
Codepen example with your data [here](http://codepen.io/David_Leitch/pen/ciAEJ “http://codepen.io/David_Leitch/pen/ciAEJ”)
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.