Friday 20 June 2014

Select only 3 options in dropdown jquery php

Select only 3 options in dropdown jquery php

<script>

$("#destination_airport").on("change", function()
{
    var msg = $("#msg");
   
    var count = 0;
   
    for (var i = 0; i < this.options.length; i++)
    {
        var option = this.options[i];
       
        option.selected ? count++ : null;
       
        if (count > 3)
        {
            option.selected = false;
           
            msg.html("Please select at most three options.");
        }
    }
});
</script>

Thursday 19 June 2014

File or Image validation in codeigniter in php

File or Image validation in codeigniter in php


$this->form_validation->set_rules('image','Image','file_required|file_size_max[500]|file_allowed_type[image]');

Wednesday 18 June 2014

Calender in php

Calender in php, codeigniter

<?
if($_POST)
{
    $day=01;
    $month=$_POST['month'];
    $year=$_POST['year'];
}
else
{
    $day=date('d');
    $month=date('m');
    $year=date('Y');
}

$prev_month=$month-1;
$next_month=$month+1;

$prev_year=$year;
$next_year=$year;

if($prev_month==0)
{
    $prev_month=12;
    $prev_year=$year-1;
}
if($next_month==13)
{
    $next_month=1;
    $next_year=$year+1;
}

$days_to_add=date('N',strtotime(date('l',strtotime($day.'-'.$month.'-'.$year))));

($days_to_add==7) ? $days_to_add=0 : '';

$num_days=date('t',strtotime($day.'-'.$month.'-'.$year));

$weeks=ceil(($num_days+$days_to_add)/7);

$days=array(1=>'Mon',2=>'Tue',3=>'Wed',4=>'Thu',5=>'Fri',6=>'Sat',7=>'Sun');

$date_to_display=1;
echo "<form action='' method='post'> <input type='text' name='month' value='".$prev_month."' hidden/><input type='text' name='year' value='".$prev_year."' hidden/><input type='submit' name='next' value='Prev'/></form> ... <form action='' method='post'> <input type='text' name='month' value='".$next_month."' hidden/><input type='text' name='year' value='".$next_year."' hidden/><input type='submit' name='next' value='Next'/> </form>";

echo "<br><br>Calender for ".date('M',strtotime($day.'-'.$month.'-'.$year))." ,$year<br><br>";
echo "<table cellpadding='3'>";
echo "<tr>";
for($i=1;$i<=7;$i++)
{
echo "<td>".$days[$i]."</td>";
}
echo "<tr>";

for($i=1;$i<=$weeks;$i++)
{
    echo "<tr>";

        for($j=1;$j<=7 && $date_to_display<=$num_days;$j++)
        {
            if($i==1)
            {
                if($days_to_add>1)
                {
                    echo "<td></td>";
                    $days_to_add--;
                }
                else
                {
                    echo "<td>$date_to_display</td>";
                    $date_to_display++;
                }
            }
            else
            {
                echo "<td>$date_to_display</td>";
                $date_to_display++;
            }
        }

    echo "</tr>";
}
echo "</table>";

?>