how to fire onchange event in chosen prototype javascript select box?

前端 未结 2 1393
陌清茗
陌清茗 2021-01-06 08:35

I am using chosen prototype for select box. Now i want to fire onchange event on that select box. here is the link for chosen prototype

How to do this. please help m

相关标签:
2条回答
  • 2021-01-06 09:16

    In this line you have used $() with a class name, which it does not support.

    Event.observe($(".chzn-select"),'change', function(){
    

    A class name can be used multiple times so an array is returned from $$(), here is one way to work with arrays.

    $$(".chzn-select").invoke('observe', 'change', function() {
        ...
    });
    

    I haven't used Chosen before; it's instructions say it needs to be setup so you might have to do this outside of the change event.

    document.observe('dom:loaded', function() {
        $$(".chzn-select").each(function(select) {
            new Chosen(select);
        });
    });
    
    0 讨论(0)
  • 2021-01-06 09:27

    use the "addEventListener" method on the select box object.

    EDIT - here's an example:

    document.getElementById('selecboxid').addEventListener('change', SomeFunction(), false);
    
    0 讨论(0)
提交回复
热议问题