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>";

?>

Saturday, 31 May 2014

sql for get data from data base in codeigniter

public function name()
{
return $this->db->select('*')->from('tablename')->where(condition)->get()->result();
}

Wednesday, 11 September 2013

Enable or Disable Text field when check the check box in php

//Enable or Disable Text field when check the check box in php

<html>
<head>
<title>bnr</title>
<script language="JavaScript">
<!--

function enable_text(status)
{
status=!status;
document.f1.other_text.disabled = status;
}
//-->
</script>
</head>
<body onload=enable_text(false);>

<form name=f1 method=post>
<input type="checkbox" name=others onClick="enable_text(this.checked)" >Others
<input type=text name=other_text>
</form>

</body>
</html>

Enable and Disable submit button when click on radio button

// Enable and Disable submit button when click on radio button



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <label>
      <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0" onclick="form1.b1.disabled=false" />
      yes</label>
    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_1" onclick="form1.b1.disabled=true" />
      no</label>
  </p>
  <p>
    <input type="submit" name="b1" id="b1" value="Submit"
    disabled="disabled" />
  </p>

</form>
</body>
</html>

Display in Drop down list from mysql database in php

//Display in Drop down list from mysql database in php 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('bnr');

$sql = "SELECT name FROM reg";
$result = mysql_query($sql);

echo "<select name='name'>";
while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['name'] ."'>" . $row['name'] ."</option>";
}
echo "</select>";

?>
</body>
</html>