namratha
namratha

Reputation: 672

Datepicker using CodeIgniter JavaScript

How to use date picker in Codeigniter?
My view part looks like this

<html>
<head>

<link  href="css/CalendarControl.css" rel="stylesheet" type="text/css">

<script language="javascript" src="js/CalendarControl.js"></script>
</head>
<body>
<table>
<tr>

<td><input name="txtdatefrom" type="text" id="txtdatefrom" onClick="return showCalendarControl(this);" style="background:#fff;border:1px solid #999;color:#999; text-align:center" value="From" onKeyPress="return disableEnterKey(event)"/></td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<td><input name="txtdateto" type="text" id="txtdateto" onClick="return showCalendarControl(this);" style="background:#fff;border:1px solid #999;color:#999; text-align:center" value="To" onKeyPress="return disableEnterKey(event)"/></td>
<td><input type="submit" value="submit" name="submit" id="submit" /></td>

</tr>
</table>
</body>
</html>

And my controller

public function calender(){

    $this->load->view('news/calender1');
}

Upvotes: 1

Views: 8119

Answers (4)

savaj patel
savaj patel

Reputation: 1

include datepicker js and see the result.

<div class="text">
<?php
$data = array(
    'name' => "registration_date",
    'id' => "registrationDate",
    'class' => "datepicker",
    'readonly' => "true",
    'value' => $this->input->post('registration_date')
);
echo form_input($data);
?>
<span class="text-error"><?php
echo form_error('registration_date');
?></span></div>

Upvotes: 0

user5907059
user5907059

Reputation:

Download the jquery.ui for datepicker from the internet and put the file in your folder.the file is stored in assessts/js/jquery_ui.the stored location is on your wish

1. jquery-ui.css
2. jquery-ui.js
3. jquery-ui.min.js

provide the css link in head section

<link href="<?php echo base_url('assests/js/jquery_ui/jquery-ui.css');?>" rel="stylesheet">

provide the javascript in body section

<script src="<?php echo base_url('assests/js/jquery_ui/jquery-ui.js');?>"></script>
    <script src="<?php echo base_url('assests/js/jquery_ui/jquery-ui.min.js');?>"></script>  

your code be look like this

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <link href="<?php echo base_url('assests/js/jquery_ui/jquery-ui.css');?>" rel="stylesheet">

    <script type="text/javascript">
        $(function(){
            $("#date").datepicker();
        });
    </script>
    </head>
    <body>
    <label>Enter a date: </label><input id="date">

<script src="<?php echo base_url('assests/js/jquery_ui/jquery-ui.js');?>"></script>
        <script src="<?php echo base_url('assests/js/jquery_ui/jquery-ui.min.js');?>"></script>  

 </body>
    </html>

and finally in control load the view and javascript library

Upvotes: 0

Dimple
Dimple

Reputation: 45

install datecker's js then call function datepicker() using jQuery on id on which you want date.

Upvotes: 1

Digital Alchemist
Digital Alchemist

Reputation: 2332

This might help you out: Using Datetime picker

Or for Codeigniter:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="development-bundle/themes/ui-lightness/jquery.ui.all.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>jQuery UI Datepicker Example 1</title>
<script type="text/javascript" src="development-bundle/jquery-1.4.2.js"></script>
<script type="text/javascript" src="development-bundle/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="development-bundle/ui/jquery.ui.datepicker.js"></script>
<script type="text/javascript">
    $(function(){
        $("#date").datepicker();
    });
</script>
</head>
<body>
<label>Enter a date: </label><input id="date">
</body>
</html>

Upvotes: 0

Related Questions