Page 1 of 1

[HELP] Multiple Datepicker in single page

Posted: Sat Jul 19, 2014 11:10 am
by Grandong
i have form with multiple datepicker
and id using loop

Include

Code: Select all

  <link href="<?php echo base_url();?>assets/ws/jquery-ui.css" type="text/css" rel="stylesheet" />
  <script src="<?php echo base_url();?>assets/ws/jquery-1.9.1.js"></script>
  <script src="<?php echo base_url();?>assets/ws/jquery-ui.js"></script>
and this my code :

Code: Select all

                  <div class="form-group">
                    <label><?= $json_results['required']['birthdatea'.$i]["FieldText"]; ?></label>
                    <div class="input-group">
                      <span class="input-group-addon">
                        <i class="fa fa-calendar"></i>
                      </span>
                      <input type="text" id="birthdatea<?= $i; ?>" class="form-control" name="birthdatea[]" placeholder="">
<script type="text/javascript">
var s = $.noConflict();
s(document).ready(function(){
    s("#birthdatea<?= $i; ?>").datepicker({ 
        dateFormat: "yy-mm-dd",
        changeMonth: true,
        autoSize: true
    });  
});
</script>
                    </div>
                  </div> 
id birthdatea1 work, but birthdatea2 datepicker not work, please help me

Re: [HELP] Multiple Datepicker in single page

Posted: Mon Jul 21, 2014 9:10 am
by Christopher
Grandong wrote:id birthdatea1 work, but birthdatea2 datepicker not work, please help me
HOW is is not working?

A wild guess is that it is working but sending both dates in the same form var. Maybe:

Code: Select all

<input type="text" id="birthdatea<?= $i; ?>" class="form-control" name="birthdatea<?= $i; ?>[]" placeholder="">

Re: [HELP] Multiple Datepicker in single page

Posted: Thu Aug 21, 2014 6:08 pm
by thinsoldier
Is your datepicker a jQuery plugin?

Will all your datepickers use the same options?

If yes to both questions it's very likely you can simple apply the datepicker to all date fields with a single call and don't need to include it within the php loop and don't need to give each date field a unique id.

Code: Select all

<input type="text" class="form-control jq-datepicker" name="birthdatea[]" placeholder="">
<input type="text" class="form-control jq-datepicker" name="birthdatea[]" placeholder="">
<input type="text" class="form-control jq-datepicker" name="birthdatea[]" placeholder="">
<input type="text" class="form-control jq-datepicker" name="birthdatea[]" placeholder="">

Code: Select all

s(document).ready(function( $ ){
    $('.jq-datepicker').datepicker({
        dateFormat: "yy-mm-dd",
        changeMonth: true,
        autoSize: true
    });  
})