简体   繁体   中英

grails datepicker value via ajax

How can I set an onchange event to a tag?

I want to transfer the new value to the server without klicking the submit button (therefore in an ajax way)

Grails datepicker tag implemention renders a fixed number of select tags based on the precision that you choose. However, no onchange attribute is added to any of these select tags. The id of each select tag is the id that you specify in the datepicker tag appended by the type of data that each select shows. Eg. the select box for day has id "yourDatepickerTagId_day", the month select tag has id "yourDatepickerTagId_month" etc. To bind the "change" event to any of these select tags you will have to use some custom javascript to handle these events. If you use jQuery, you can use something like this:

    $(document).ready(function(){
       $("select[id ^= yourDatepickerTagId]").change(function (){
          // Do your stuff here...
       });
    });

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