0

This is my button

<div class="block">
<?=form_line(lang('start_date'),form_input('start_date', date('Y-m-d')))?>
<a id="Add">Click to add textbox</a>
</div>

<script type="text/javascript">
$(document).ready(function() {

$('input[name=start_date]').datepicker({maxDate: constants.MAX_YEAR+'-12-31', changeYear: true, changeMonth: true, dateFormat:'yy-mm-dd'});
$('input[name=end_date]').datepicker({maxDate: constants.MAX_YEAR+'-12-31', changeYear: true, changeMonth: true, dateFormat:'yy-mm-dd'});

 $("#Add").on("click", function() {
        var row = '<?=form_line(lang('start_date'),form_input('start_date', date('Y-m-d')))?>';
        $('block').append(row)
    });

}) // eof ready
</script>

How do i append form_line(lang('start_date'),form_input('start_date', date('Y-m-d')))?>

while clicking on the link "Click to add textbox"

1
  • What is the goal exactly - to add a new datepicker with each click of the "add textbox" right? Commented Jun 19, 2018 at 15:38

1 Answer 1

1

Do something like this for dynamically added elements

$('body').on('focus',".datepick", function(){
    $(this).datepicker({
      maxDate: constants.MAX_YEAR+'-12-31', 
      changeYear: true, 
      changeMonth: true, 
      dateFormat:'yy-mm-dd'
     });
});​

Just add class datepick to your form input like this :

$(document).ready(function() {
     $("#Add").on("click", function() {
        var row = '<?=form_line(lang('start_date'),form_input('start_date', date('Y-m-d'),'class="datepick"'))?>';
        $('block').append(row)
    });

});
Sign up to request clarification or add additional context in comments.

1 Comment

pls don't hesitate to accept my answer as answer if its help you really

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.