CodeIgniter Forums
Change a field from drop-down to calendar - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Change a field from drop-down to calendar (/showthread.php?tid=66130)



Change a field from drop-down to calendar - Gagan - 09-10-2016

Hello guys,

I'm having a form in which there are two field Date of Birth and Date of Retirement (which are drop-down field) :-
(I'm having an option to fix the date of birth and date of retirement  field {Start date and end date} from admin panel)

Date of Birth:



PHP Code:
<div class="row-form">
 
             <div class="span3">Date Of Birth<font color="#FF0000">*</font></div>
 
             <div class="span9">
 
                 <?php
               
// Start date
 
                $date $dob_start_date;
 
                // End date
 
                $end_date $dob_end_date;
 
                ?>
                 <select name="dob" id="dob" required>
                 <?php
                 
while (strtotime($date) <= strtotime($end_date)) {
 
                    ?>
                <option value="<?=$date?><?php if($dob==$date){ echo "selected";}?>><?=date("d-m-Y"strtotime($date));?></option>
                <?php
                 $date 
date ("Y-m-d"strtotime("+1 day"strtotime($date)));
 
                }
 
             ?>
              </select>
              </div>
<div class="clear"></div>

            </div> 



Date of Retirement


PHP Code:
<div class="row-form">
 
             <div class="span3">Date Of <?php if($user_type=='S'){ echo $emp_type;}else{ echo $_REQUEST['element_11'];}?><font color="#FF0000">*</font></div>
              <div class="span9">
                 <?php
               
// Start date
 
                $date1 $dor_start_date;
 
                // End date
 
                $end_date1 $dor_end_date;
 
                ?>
                 <select name="dor" id="dor" required>
                 <?php
                 
while (strtotime($date1) <= strtotime($end_date1)) {
 
                    ?>
                <option value="<?=$date1?><?php if($dor==$date1){ echo "selected";}?>><?=date("d-m-Y"strtotime($date1));?></option>
                <?php
                 $date1 
date ("Y-m-d"strtotime("+1 day"strtotime($date1)));
 
                }
 
             ?>
              </select>
              </div>
              <em style="margin-left:260px">( eg: enter date in mentioned format DD-MM-YYYY )</em>
              <div class="clear"></div>
            </div>
            <div class="row-form">
              <div class="span3"><?php if($user_type=='S'){ echo $emp_type;}else{ echo $_REQUEST['element_11'];}?> from the Office of<font color="#FF0000">*</font></div>
              <div class="span9">
                <select name="location" id="location" required <?=$readonly;?>>
                <option value="">--Select Location--</option>
                <?php foreach ($get_locations as $get_locations_list): ?>
                <option value="<?=$get_locations_list['id'];?><?php if($get_locations_list['id']==$location){ echo "selected";}?>><?=$get_locations_list['location'];?></option>
                <?php endforeach ?>
                </select>
              </div>
              <div class="clear"></div>
            </div> 




I want to change these fields to calendar. Please help me guys how to change this. Attached  herewith two pics showing position explained above.


RE: Change a field from drop-down to calendar - Wouter60 - 09-10-2016

I think you should look for a "Datepicker" javascript. There's one in jQuery UI's library.
Check this: https://jqueryui.com/datepicker/
A tip for posting blocks of code: use the Code or PHP-code buttons on the toolbar of this forum's text-editor.


RE: Change a field from drop-down to calendar - Gagan - 09-10-2016

(09-10-2016, 08:39 AM)Wouter60 Wrote: I think you should look for a "Datepicker" javascript. There's one in jQuery UI's library.
Check this: https://jqueryui.com/datepicker/
A tip for posting blocks of code: use the Code or PHP-code buttons on the toolbar of this forum's text-editor.

Thanks buddy, edited the form.

If we use date picker option will it use the start and end dates as defined in the admin panel


RE: Change a field from drop-down to calendar - Wouter60 - 09-10-2016

It will. The jQuery datepicker accepts a minDate() and a maxDate() setting.