简体   繁体   中英

Call a ajax function on the elselect drop down change

I am using elSelect with mootools to change the look and fell of a select box. My problem is how can i call an ajax function when select box value changes?

<script type="text/javascript">
    window.addEvent('domready', function() {
        var mySelect = new elSelect( {container : 'someId'} );
    });
</script>

Thanks in advance

Since elSelect changes the HTML structure to replace the dropdown, you can't use the change event set on the original dropdown. The documentation doesn't show any way to bind events to the replaced dropdown.

I'm not at all familiar with the way mootools works, but I notice in the source of the plugin that it has several event handlers defined, among which is onOptionClick . This gets triggered every time the user clicks an option in the dropdown. You can piggyback on top of it - change the code in that function to also trigger your ajax request.

Another option would be analyse the HTML structure of the injected elements - you can start from the id you give the constructor and look for .option elements inside it. You can them poll them for changes at fixed intervals (using setInterval ) and send ajax requests when you see the value has changed. Or you can add click handlers to each option and take it from there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM