javascript - jQuery datepicker not working on dynamically generated HTML -


i have code:

<div id="infants-data"></div>  for( var = 1; <= 10; i++) {          var currinfantdatafield = '' +         '<div class="field">infant ' + + ': ' +           '<div style="width:600px">' +            '<select id="infant-'      + + '-title" style="border:solid 1px #cccccc;">'+             '<option selected>--title--</option>'    +            '<option value="master">master</option>' +             '<option value="miss">miss</option>'     +              '</select>' +           '<input type="text" id="infant-' + + '-surname" placeholder="surname"  style="width:110px; border:solid 1px #cccccc;">' +           '<input type="text" id="infant-' + + '-othernames" placeholder="othernames"  style="width:120px; border:solid 1px #cccccc;">' +            '<input type="text" id="infant-' + + '-birthdate"  placeholder="date of birth"  style="width:120px; border:solid 1px #cccccc;" readonly>' +           '</div>' +         '</div>';          document.getelementbyid('infants-data').innerhtml += currinfantdatafield;          jquery( "#infant-" + + "-birthdate").datepicker({          changemonth: true,           changeyear: true,          yearrange:'1900:<?php echo ( date('y') - 2 ); ?>',         onselect: (function(){dosomethingusefulwithfield("infant-" + + "-birthdate")})         }); } 

for reason can't explain, datepicker not working.

p.s have tried this , several others did not work in case, hence asking this.

rewrite .datepicker() traverse down $(document), find respected new 'html'

    jquery("#infant-" + + "-birthdate", document).datepicker({          changemonth: true,           changeyear: true,          yearrange:'1900:<?php echo ( date('y') - 2 ); ?>',         onselect: (function(){             dosomethingusefulwithfield("infant-" + + "-birthdate")         })     }); 

that, or check make sure haven't got javascript errors prior .datepicker() initialisation 'blocking' execution.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -