Search code examples
javascriptprototypejsprototype-chosen

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


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 me.

<script type="text/javascript" src="/js/Event.simulate.js"></script>
<script src="/js/prototype.js" type="text/javascript"></script>
<script src="/chosen/chosen.proto.js" type="text/javascript"></script>


<div class="side-by-side clearfix" style="margin-bottom:14px;">

        <select data-placeholder="Select Loacation"  class="chzn-select" tabindex="2" name="source">
          <option value="">Select Loacation</option>
          <option value="">option1</option>
          <option value="">option2</option>
        </select>
  </div>



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

//alert($(".chzn-select").chosen());

})

Solution

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

    EDIT - here's an example:

    document.getElementById('selecboxid').addEventListener('change', SomeFunction(), false);