Search code examples
jquerygrailsdatepickergsp

How can i access the date picker with their class and then id


I am using three date-picker of bootstrap which is using the following code to initiate layout and plugin

   <script> 
    jQuery(document).ready(function() { 
    // initiate layout and plugins 
    $('.date-picker').datepicker({ 
    rtl : Metronic.isRTL(), 
    autoclose : true 
    }); 

    }); 
    </script>

How can i access the date picker with their id as i have a date picker with id birthdate and i want to set it's enddate without affecting other date pickers the code for birth date date picker is as foillows

<MyUI:datePicker  id="birthDate" name="birthDate"
        label="${message(code: 'BP.birthDate.label', default: 'Birth Date')}"
        required="true"
        value="${BP?.birthDate ? BPInstance?.birthDate?.format('yyyy-MM-dd') : new Date().format('yyyy-MM-dd')}"
        labelCol="4" elementCol="8" />

Please someone help


Solution

  • You can access only your "birthday" field with

    $('#birthDate').datepicker({ //...
    

    The other datepickers should stay untouched.

    If you don't want to work with the ID you have to use something like this, but you have to know on which "position" the "birthDate"-Field is (check if the id is birthDate)... I think you won't get around using the ID.

    $('.date-picker').each(function(){
        alert($(this).attr('id'));
    });