Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.chosen().change() not working #383

Closed
gav-fyi opened this issue Dec 7, 2011 · 8 comments
Closed

.chosen().change() not working #383

gav-fyi opened this issue Dec 7, 2011 · 8 comments

Comments

@gav-fyi
Copy link

gav-fyi commented Dec 7, 2011

Hi, I am wanting to update the the options in one chosen based on the value selected in another, using AJAX.

I have the underlying AJAX code working great on standard selects, but when I try either of the following two code snippets to trigger a change, it does not work.

I get the alert() on page load, but not when I change the value of the select with id "categories"

[code]

$("#categories").chosen().select(alert());
$("#categories").chosen().change(alert());

[/code]

@gav-fyi
Copy link
Author

gav-fyi commented Dec 7, 2011

Fixed by wrapping it in

$(document).ready(function() {

});

@gav-fyi gav-fyi closed this as completed Dec 7, 2011
@samkuehn
Copy link

samkuehn commented Feb 2, 2012

I am seeing the same behavior - I have it wrapped in:

$(document).ready(function() {
    $(".chzn-select").chosen().select(alert());
});

I am using jquery 1.7.1

@bkuhl
Copy link

bkuhl commented Jun 17, 2012

@samkuehn

Sam - were you able to resolve this? I'm working with it now and the below code is not logging anything in my console.

$(document).ready(function () {
    $('#season').chosen().change(function () {
        console.log('asdf');
    });
});

@samkuehn
Copy link

@bkuhl It has been some time but I think this is what ended up working for me:

$(".chzn-select").chosen().change(function (event) {
    log('change', event, $(event.target).val());
});

@iBorodai
Copy link

iBorodai commented Aug 9, 2012

it helps for me just roll back to 0.9.5 version :)

@phqvince
Copy link

phqvince commented Aug 25, 2016

  var choice, close_link,
                _this = this;
            choice = $('<li />', {
                "class": "search-choice"
            }).html("<span>" + item.html + "</span>");
            if (item.disabled) {
                choice.addClass('search-choice-disabled');
            } else {
                close_link = $('<a />', {
                    "class": 'search-choice-close',
                    'data-option-array-index': item.array_index
                });
                close_link.bind('click.chosen', function(evt) {
                    return _this.choice_destroy_link_click(evt);
                });
                choice.append(close_link);

want to ask,how to addClass to <span>?

@diparthshah
Copy link

diparthshah commented May 21, 2018

This works perfectly for me. If someone was looking for CoffeeScript implementation, its here:

$('.myselect').chosen().change(
    (event) ->
        console.log "data changed"
)  

@amiranbari
Copy link

i have same thing here. no solution worked for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants