article

Friday, October 16, 2015

Jquery UI Datepicker Change background color Unavailable date

Jquery UI Datepicker Change background color Unavailable date
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Change background color Unavailable date</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.17/themes/start/jquery-ui.css">
<script type='text/javascript' src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.17/jquery-ui.min.js"></script>
  <style type='text/css'>
    .ui-datepicker td.ui-state-disabled>span{background:#F70C0C;}
.ui-datepicker td.ui-state-disabled{opacity:100;}
  </style>
<script type='text/javascript'>//<![CDATA[
var unavailableDates = ["17-10-2015", "18-10-2015", "20-10-2015"];
function unavailable(date) {
    dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
    if ($.inArray(dmy, unavailableDates) == -1) {
        return [true, ""];
    } else {
        return [false, "", "Unavailable"];
    }
}
$(function() {
    $("#iDate").datepicker({
        dateFormat: 'dd MM yy',
        beforeShowDay: unavailable
    });

});
//]]> 
</script>
</head>
<body>
  <input id="iDate">
</body>
</html>

Jquery Datepicker Load Specified Date


Jquery Datepicker Load Specified Date
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Datepicker</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/start/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <script>
  $(function() {
var availableDates = [
<?php 
for ($x = 0; $x <= 10; $x++) {
?>
"<?php echo $x; ?>-10-2015",
<?php } ?>];

function available(date) {
  dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
  if ($.inArray(dmy, availableDates) != -1) {
    return [true, "","Available"];
  } else {
    return [false,"","unAvailable"];
  }
}

$('#date').datepicker({ 
 beforeShowDay: available,
 // The hidden field to receive the date
    altField: "#dateHidden",
    // The format you want
    altFormat: "yy-mm-dd",
    // The format the user actually sees
    dateFormat: "dd/mm/yy",
    onSelect: function (date) {
        alert(date);        
    } 
}); 
});
  </script>
</head>
<body>
<div id="date"></div>
 Not hidden just for the sake of demonstration: <input type="text" id="dateHidden" />
</body>
</html>

Saturday, September 5, 2015

Execute a Python File in Notepad ++?

Execute a Python File in Notepad ++

To set up Notepad++ for Python developing

1. Install http://tutorial101.blogspot.com/2015/09/notepad-python-script.html
2. Create a batch script that would run a python script





Path
C:\Python27\pt.bat


Code pt.bat

@ECHO OFF
C:\Python27\python.exe "%1"
echo.
PAUSE
@ECHO ON 


3. Run notepadd++ ex. helloword.py

paste url C:\Python27\pt.bat "$(FULL_CURRENT_PATH)"
and assign a shortcut. Press that shortcut now with a python file opened

Notepad++ Python Script

Notepad++ Python Script

A Python Scripting plugin for Notepad++.

Complete easy script access to all of the editor's features (including absolutely everything in Scintilla). Configurable menus and toolbar options, assign shortcuts to scripts.

Features
Full scripting access to all Notepad++ features with normal Python function calls (e.g. notepad.new(), notepad.open('filename.txt') )
Full scripting access to all Scintilla features (the edit component in N++)
Configurable menus and toolbars - assign shortcuts to scripts
Respond to Notepad++ and Scintilla events with script functions
Call other plugin menu commands programmatically
Scriptable regular expression search and replace

Notepad++ Python Script Web Site>

Friday, September 4, 2015

AngularJS Forms Custom Model Update Triggers

AngularJS Forms Custom Model Update Triggers

The novalidate attribute

1. updateOn option of the ng-model-options directive. The model value updates when the focus is lost.
2. debounce option delays the model update. update the model after 250 milliseconds
3. updateOn and debounce option. Setting the debounce value of blur event to ‘0’ indicates that the model trigger immediate update when it is out of focus.
<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>AngularJS Custom Model Update</title>  
 </head>
 <body ng-app="formApp">
  <div ng-controller="FormController">
   <form novalidate>
    Name : <input type="text" ng-model="employee.name" ng-model-options="{updateOn:'blur'}"/></br>
    Gender : <input type="text" ng-model="employee.gender" ng-model-options="{debounce:250}"/></br>
    E-mail : <input type="email" ng-model="employee.email" ng-model-options="{updateOn:'blur',debounce:{blur:0} }"/></br>
   </form>
     <p>Name : {{employee.name}}</p>
   <p>Gender : {{employee.gender}}</p>
   <p>Email : {{employee.email}}</p>
  </div>
  </div>
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
 <script type="text/javascript">
  var app = angular.module('formApp', []);
  app.controller('FormController', function($scope) {
   $scope.employee = {};

  });
 </script>
</body>
</html>

AngularJS

AngularJS


AngularJS is a JavaScript framework. It can be added to an HTML page.

AngularJS extends HTML attributes with Directives, and binds data to HTML with Expressions.

AngularJS is perfect for Single Page Applications (SPAs).

AngularJS is easy to learn.
https://angularjs.org/

Saturday, August 15, 2015

TiTatoggle : CSS Toggle Button for Bootstrap

TiTatoggle : CSS Toggle Button for Bootstrap

Pure css toggle buttons based on the bootstrap checkbox pattern.The Pattern is the same as Twitter-Bootstrap.

Demo     Download

Saturday, August 1, 2015

Example Bootstrap Progress Bar

Example Bootstrap Progress Bar
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bootstrap Progress Bar</title>
<!-- these are library file of css-->
<link rel="stylesheet" href="bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- this is library file of Jquery-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!--this is library file of javascript-->
<script src="bootstrap/3.3.5/js/bootstrap.min.js"></script>
<!-- this css used for body-->
<script src="js/modernizr.js" type="text/javascript"></script>
</head>
<body>
<script>
$(document).ready(function() {
if (!Modernizr.meter) {
alert('Sorry your browser does not support HTML5 progress bar');
} else {
var progressbar = $('#progressbar'),
max = progressbar.attr('max'),
time = (1000 / max) * 5,
value = progressbar.val();
var loading = function() {
value += 1;
addValue = progressbar.val(value);
$('.progress-value').html(value + '%');
if (value == max) {
clearInterval(animate);
}
};
var animate = setInterval(function() {
loading();
}, time);
}
;
});
</script>
<style>
body {
background-color: #f9f9f9;
}
/*=== This is a hole container part===*/
.container{
width: 890px;
height:130px;
}
/*=== This is a hole progress bar css===*/
.demo-wrapper {
width: 500px;
margin: 30px auto 0;
}
.html5-progress-bar {
padding: 15px 15px;
border-radius: 3px;
background-color: #626262;
box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, .2);
}
.html5-progress-bar progress {
background-color: #F1F1F1;
border: 0;
width: 80%;
height: 18px;
border-radius: 9px;
}
.html5-progress-bar progress::-webkit-progress-bar {
background-color: #f3f3f3;
border-radius: 9px;
}
.html5-progress-bar progress::-webkit-progress-value {
background: #5CB85C;
background: -moz-linear-gradient(top, #5CB85C 0%, #5CB85C 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#5CB85C), color-stop(100%,#a5c956));
background: -webkit-linear-gradient(top, #5CB85C 0%,#a5c956 100%);
background: -o-linear-gradient(top, #5CB85C 0%,#a5c956 100%);
background: -ms-linear-gradient(top, #5CB85C 0%,#a5c956 100%);
background: linear-gradient(to bottom, #5CB85C 0%,#a5c956 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#5CB85C', endColorstr='#a5c956',GradientType=0 );
border-radius: 9px;
}
.html5-progress-bar progress::-moz-progress-bar {
background: #5CB85C;
background: -moz-linear-gradient(top, #5CB85C 0%, #a5c956 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#5CB85C), color-stop(100%,#a5c956));
background: -webkit-linear-gradient(top, #5CB85C 0%,#a5c956 100%);
background: -o-linear-gradient(top, #5CB85C 0%,#a5c956 100%);
background: -ms-linear-gradient(top, #5CB85C 0%,#a5c956 100%);
background: linear-gradient(to bottom, #5CB85C 0%,#a5c956 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#5CB85C', endColorstr='#a5c956',GradientType=0 );
border-radius: 9px;
}
/*=== This is a % value of progress bar css===*/
.html5-progress-bar .progress-value {
padding: 0px 5px;
line-height: 20px;
margin-left: 5px;
font-size: .9em;
color: #F5F5F5;
height: 18px;
float: right;
}
</style>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="demo-wrapper html5-progress-bar">
<div class="progress-bar-wrapper">
<progress id="progressbar" value="0" max="100"></progress>
<span class="progress-value">0%s</span>
</div>
</div>
</div>
</div>
</div>

</body>
</html>

Thursday, July 23, 2015

Example Bootstrap Carousel

Example Bootstrap Carousel
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example of Bootstrap 3 Carousel</title>
<!-- these are library file of css-->
<link rel="stylesheet" href="bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- this is library file of Jquery-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!--this is library file of javascript-->
<script src="bootstrap/3.3.5/js/bootstrap.min.js"></script>
<!-- this css used for body-->
<style type="text/css">
h2{
margin: 0;
color: #666;
padding-top: 90px;
font-size: 52px;
font-family: "trebuchet ms", sans-serif;
}
.item{
background: #333;
text-align: center;
height: 300px !important;
}
.carousel{
margin-top: 20px;
}
.bs-example{
margin: 20px;
}
</style>
</head>
<body>
<!--this DIV use for carousel and sliding time-->
<div class="bs-example">
<div id="myCarousel" class="carousel slide" data-interval="3000" data-ride="carousel">
<!-- this DIV use for carousel indicators for slider-->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!--Wrapper for carousel items which are show in output form-->
<div class="carousel-inner">
<!--this is first slider page-->
<div class="active item">
<h2>Slide 1</h2>
<div class="carousel-caption">
<h3>First slide label</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
<!-- this is second slider page-->
<div class="item">
<h2>Slide 2</h2>
<div class="carousel-caption">
<h3>Second slide label</h3>
<p>Aliquam sit amet gravida nibh, facilisis gravida odio.</p>
</div>
</div>
<!-- this is third slider page-->
<div class="item">
<h2>Slide 3</h2>
<div class="carousel-caption">
<h3>Third slide label</h3>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
</div>
</div>
</div>
<!-- this is carousel controls for used of next and previous pages slider-->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</body>
</html>

Tuesday, July 21, 2015

Launch Bootstrap Modal on page load

Launch Bootstrap Modal on page load JS
<script type="text/javascript">
    $(window).load(function(){
        $('#myModal').modal('show');
    });
</script>
HTML
<div class="modal hide fade" id="myModal">
  <div class="modal-header">
    <a class="close" data-dismiss="modal">×</a>
    <h3>Modal header</h3>
  </div>
  <div class="modal-body">
    <p>One fine body…</p>
  </div>
  <div class="modal-footer">
    <a href="#" class="btn">Close</a>
    <a href="#" class="btn btn-primary">Save changes</a>
  </div>
</div>

Disable odd checkbox of Checkbox list using jQuery

Disable odd checkbox of Checkbox list using jQuery
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Disable odd checkbox of Checkbox list using jQuery</title>
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
  <style type='text/css'>
    body {
    font-family: Calibri;
    font-size : 12pt;
    padding :10px;
}
  </style>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$(document).ready(function () {
    $("input[name='tech']").filter(':even').attr('disabled', true);
    $("input[name='hobbies']").filter(':odd').attr('disabled', true);
});
});//]]>  

</script>
</head>
<body>
  <b>1st Checkbox List: </b>
<br/>
<input type="checkbox" name="tech" value="jQuery" />jQuery
<br/>
<input type="checkbox" name="tech" value="JavaScript" />JavaScript
<br/>
<input type="checkbox" name="tech" value="Prototype" />Prototype
<br/>
<input type="checkbox" name="tech" value="Dojo" />Dojo
<br/>
<input type="checkbox" name="tech" value="Mootools" />Mootools
<br/>
<br/>
<b>2nd Checkbox List: </b>
<br/>
<input type="checkbox" name="hobbies" value="Sports" />Sports
<br/>
<input type="checkbox" name="hobbies" value="Racing" />Racing
<br/>
<input type="checkbox" name="hobbies" value="Singing" />Singing
<br/>
<input type="checkbox" name="hobbies" value="Writing" />Writing
<br/>
<input type="checkbox" name="hobbies" value="Travelling" />Travelling
<br/>
<input type="checkbox" name="hobbies" value="Cooking" />Cooking
<br/>
</body>
</html>

Image Preview Thumbnails before upload using jQuery & PHP

Image Preview Thumbnails before upload using jQuery & PHP
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script>
$(document).ready(function(){
    $('#file-input').on('change', function(){ //on file input change
        if (window.File && window.FileReader && window.FileList && window.Blob) //check File API supported browser
        {
            $('#thumb-output').html(''); //clear html of output element
            var data = $(this)[0].files; //this file data
            
            $.each(data, function(index, file){ //loop though each file
                if(/(\.|\/)(gif|jpe?g|png)$/i.test(file.type)){ //check supported file type
                    var fRead = new FileReader(); //new filereader
                    fRead.onload = (function(file){ //trigger function on successful read
                    return function(e) {
                        var img = $('<img/>').addClass('thumb').attr('src', e.target.result); //create image element 
                        $('#thumb-output').append(img); //append image to output element
                    };
                    })(file);
                    fRead.readAsDataURL(file); //URL representing the file's data.
                }
            });
            
        }else{
            alert("Your browser doesn't support File API!"); //if File API is absent
        }
    });
});
</script>
<style>
.thumb{
    margin: 10px 5px 0 0;
    width: 100px;
}
.alert-info {
  background-color: #d9edf7;
  border-color: #bce8f1;
  color: #31708f;
}
.alert {
  padding: 5px 10px;
  margin-bottom: 10px;
  border: 1px solid transparent;
  border-radius: 4px;
}
</style>
<div class="alert alert-info">
<input type="file" id="file-input" multiple=""><p></p>
<div id="thumb-output"></div>
</div>

Create Collage using jQuery

Create Collage using jQuery

find out how to create a collage using a jQuery plugin called "CollagePlus". This plugin for jQuery will arrange your images to fit exactly within a container.

How to Limit Number of Characters in Textarea using jQuery

How to Limit Number of Characters in Textarea using jQuery
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>jQuery Limit Characters in Textarea</title> 
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.js'></script>
  <style type='text/css'>
    body {
    font-family:Calibri;
}
.remaining {
    color:blue;
}
textarea {
    font-family:Calibri;
}
  </style>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$(function () {
    var nMaxLength = 150;
    $("#txtDesc").keydown(function (event) {
        LimitCharacters($(this));
    });
    $("#txtDesc").keyup(function (event) {
        LimitCharacters($(this));
    });

    function LimitCharacters(txtDesc) {
        if (txtDesc.val().length > nMaxLength) {
            txtDesc.val(txtDesc.val().substring(0, nMaxLength));
        } else {
            var nRemaining = nMaxLength - txtDesc.val().length;
            $('.remaining').text(nRemaining);
        }
    }
});
});//]]>  
</script>
</head>
<body>
  <textarea name="txtDesc" rows="4" cols="50" id="txtDesc" onDrop="return false;" style="width:70%;"></textarea>
<br/>Remaining: <b><span class="remaining">150</span></b>
</body>
</html>

Ajax Shopping Cart with PHP and jQuery

Ajax Shopping Cart with PHP and jQuery

 Create MySql Table
--
-- Table structure for table `products_list`
--

CREATE TABLE IF NOT EXISTS `products_list` (
`id` int(11) NOT NULL,
  `product_name` varchar(60) NOT NULL,
  `product_desc` text NOT NULL,
  `product_code` varchar(60) NOT NULL,
  `product_image` varchar(60) NOT NULL,
  `product_price` decimal(10,2) NOT NULL
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `products_list`
--

INSERT INTO `products_list` (`id`, `product_name`, `product_desc`, `product_code`, `product_image`, `product_price`) VALUES
(1, 'Cool T-shirt', 'Cool T-shirt, Cotton Fabric. Wash in normal water with mild detergent.', 'TSH1', 'tshirt-1.jpg', '8.50'),
(2, 'HBD T-Shirt', 'Cool Happy Birthday printed T-shirt.Crafted from light, breathable cotton.', 'TSH2', 'tshirt-2.jpg', '7.40'),
(3, 'Survival of Fittest', 'Yellow t-shirt makes the perfect addition to your casual wardrobe.', 'TSH3', 'tshirt-3.jpg', '9.50'),
(4, 'Love Hate T-shirt', 'Stylish and trendy, this crew neck short sleeved t-shirt is made with 100% pure cotton.', 'TSH4', 'tshirt-4.jpg', '10.80');

Configuration file
<?php
$db_username        = 'root'; //MySql database username
$db_password        = ''; //MySql dataabse password
$db_name            = 'test'; //MySql database name
$db_host            = 'localhost'; //MySql hostname or IP

$currency   = '₹ '; //currency symbol
$shipping_cost  = 1.50; //shipping cost
$taxes    = array( //List your Taxes percent here.
       'VAT' => 12, 
       'Service Tax' => 5,
       'Other Tax' => 10
       );

$mysqli_conn = new mysqli($db_host, $db_username, $db_password,$db_name); //connect to MySql
if ($mysqli_conn->connect_error) {//Output any connection error
    die('Error : ('. $mysqli_conn->connect_errno .') '. $mysqli_conn->connect_error);
}
Listing Products
<?php
session_start(); //start session
include("config.inc.php"); //include config file
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ajax Shopping Cart</title>
<link href="style/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
<script>
$(document).ready(function(){ 
  $(".form-item").submit(function(e){
   var form_data = $(this).serialize();
   var button_content = $(this).find('button[type=submit]');
   button_content.html('Adding...'); //Loading button text 

   $.ajax({ //make ajax request to cart_process.php
    url: "cart_process.php",
    type: "POST",
    dataType:"json", //expect json value from server
    data: form_data
   }).done(function(data){ //on Ajax success
    $("#cart-info").html(data.items); //total items in cart-info element
    button_content.html('Add to Cart'); //reset button text to original text
    alert("Item added to Cart!"); //alert user
    if($(".shopping-cart-box").css("display") == "block"){ //if cart box is still visible
     $(".cart-box").trigger( "click" ); //trigger click to update the cart box.
    }
   })
   e.preventDefault();
  });

 //Show Items in Cart
 $( ".cart-box").click(function(e) { //when user clicks on cart box
  e.preventDefault(); 
  $(".shopping-cart-box").fadeIn(); //display cart box
  $("#shopping-cart-results").html('<img src="images/ajax-loader.gif">'); //show loading image
  $("#shopping-cart-results" ).load( "cart_process.php", {"load_cart":"1"}); //Make ajax request using jQuery Load() & update results
 });
 
 //Close Cart
 $( ".close-shopping-cart-box").click(function(e){ //user click on cart box close link
  e.preventDefault(); 
  $(".shopping-cart-box").fadeOut(); //close cart-box
 });
 
 //Remove items from cart
 $("#shopping-cart-results").on('click', 'a.remove-item', function(e) {
  e.preventDefault(); 
  var pcode = $(this).attr("data-code"); //get product code
  $(this).parent().fadeOut(); //remove item element from box
  $.getJSON( "cart_process.php", {"remove_code":pcode} , function(data){ //get Item count from Server
   $("#cart-info").html(data.items); //update Item count in cart-info
   $(".cart-box").trigger( "click" ); //trigger click on cart-box to update the items list
  });
 });

});
</script>
</head>
<body>
<div align="center">
<h3>Ajax Shopping Cart Example</h3>
</div>

<a href="#" class="cart-box" id="cart-info" title="View Cart">
<?php 
if(isset($_SESSION["products"])){
 echo count($_SESSION["products"]); 
}else{
 echo 0; 
}
?>
</a>

<div class="shopping-cart-box">
<a href="#" class="close-shopping-cart-box" >Close</a>
<h3>Your Shopping Cart</h3>
    <div id="shopping-cart-results">
    </div>
</div>

<?php
//List products from database
$results = $mysqli_conn->query("SELECT product_name, product_desc, product_code, product_image, product_price FROM products_list");
//Display fetched records as you please

$products_list =  '<ul class="products-wrp">';

while($row = $results->fetch_assoc()) {
$products_list .= <<<EOT
<li>
<form class="form-item">
<h4>{$row["product_name"]}</h4>
<div><img src="images/{$row["product_image"]}"></div>
<div>Price : {$currency} {$row["product_price"]}<div>
<div class="item-box">
    <div>
 Color :
    <select name="product_color">
    <option value="Red">Red</option>
    <option value="Blue">Blue</option>
    <option value="Orange">Orange</option>
    </select>
 </div>
 
 <div>
    Qty :
    <select name="product_qty">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    </select>
 </div>
 
 <div>
    Size :
    <select name="product_size">
 <option value="M">M</option>
    <option value="XL">XL</option>
    <option value="XXL">XLL</option>
    </select>
 </div>
 
    <input name="product_code" type="hidden" value="{$row["product_code"]}">
    <button type="submit">Add to Cart</button>
</div>
</form>
</li>
EOT;

}
$products_list .= '</ul></div>';

echo $products_list;
?>
</body>
</html>
Add Cart process
<?php
session_start(); //start session
include_once("config.inc.php"); //include config file
setlocale(LC_MONETARY,"en_US"); // US national format (see : http://php.net/money_format)
############# add products to session #########################
if(isset($_POST["product_code"]))
{
 foreach($_POST as $key => $value){
  $new_product[$key] = filter_var($value, FILTER_SANITIZE_STRING); //create a new product array 
 }
 
 //we need to get product name and price from database.
 $statement = $mysqli_conn->prepare("SELECT product_name, product_price FROM products_list WHERE product_code=? LIMIT 1");
 $statement->bind_param('s', $new_product['product_code']);
 $statement->execute();
 $statement->bind_result($product_name, $product_price);
 

 while($statement->fetch()){ 
  $new_product["product_name"] = $product_name; //fetch product name from database
  $new_product["product_price"] = $product_price;  //fetch product price from database
  
  if(isset($_SESSION["products"])){  //if session var already exist
   if(isset($_SESSION["products"][$new_product['product_code']])) //check item exist in products array
   {
    unset($_SESSION["products"][$new_product['product_code']]); //unset old item
   }   
  }
  
  $_SESSION["products"][$new_product['product_code']] = $new_product; //update products with new item array 
 }
 
  $total_items = count($_SESSION["products"]); //count total items
 die(json_encode(array('items'=>$total_items))); //output json 

}

################## list products in cart ###################
if(isset($_POST["load_cart"]) && $_POST["load_cart"]==1)
{

 if(isset($_SESSION["products"]) && count($_SESSION["products"])>0){ //if we have session variable
  $cart_box = '<ul class="cart-products-loaded">';
  $total = 0;
  foreach($_SESSION["products"] as $product){ //loop though items and prepare html content
   
   //set variables to use them in HTML content below
   $product_name = $product["product_name"]; 
   $product_price = $product["product_price"];
   $product_code = $product["product_code"];
   $product_qty = $product["product_qty"];
   $product_color = $product["product_color"];
   $product_size = $product["product_size"];
   
   $cart_box .=  "<li> $product_name (Qty : $product_qty | $product_color  | $product_size ) — $currency ".sprintf("%01.2f", ($product_price * $product_qty)). " <a href=\"#\" class=\"remove-item\" data-code=\"$product_code\">×</a></li>";
   $subtotal = ($product_price * $product_qty);
   $total = ($total + $subtotal);
  }
  $cart_box .= "</ul>";
  $cart_box .= '<div class="cart-products-total">Total : '.$currency.sprintf("%01.2f",$total).' <u><a href="view_cart.php" title="Review Cart and Check-Out">Check-out</a></u></div>';
  die($cart_box); //exit and output content
 }else{
  die("Your Cart is empty"); //we have empty cart
 }
}

################# remove item from shopping cart ################
if(isset($_GET["remove_code"]) && isset($_SESSION["products"]))
{
 $product_code   = filter_var($_GET["remove_code"], FILTER_SANITIZE_STRING); //get the product code to remove

 if(isset($_SESSION["products"][$product_code]))
 {
  unset($_SESSION["products"][$product_code]);
 }
 
  $total_items = count($_SESSION["products"]);
 die(json_encode(array('items'=>$total_items)));
}
Add View Cart
<?php
session_start(); //start session
include("config.inc.php");
setlocale(LC_MONETARY,"en_US"); // US national format (see : http://php.net/money_format)
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Review Your Cart Before Buying</title>
<link href="style/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<h3 style="text-align:center">Review Your Cart Before Buying</h3>
<?php
if(isset($_SESSION["products"]) && count($_SESSION["products"])>0){
 $total    = 0;
 $list_tax   = '';
 $cart_box   = '<ul class="view-cart">';

 foreach($_SESSION["products"] as $product){ //Print each item, quantity and price.
  $product_name = $product["product_name"];
  $product_qty = $product["product_qty"];
  $product_price = $product["product_price"];
  $product_code = $product["product_code"];
  $product_color = $product["product_color"];
  $product_size = $product["product_size"];
  
  $item_price  = sprintf("%01.2f",($product_price * $product_qty));  // price x qty = total item price
  
  $cart_box   .=  "<li> $product_code –  $product_name (Qty : $product_qty | $product_color | $product_size) <span> $currency. $item_price </span></li>";
  
  $subtotal   = ($product_price * $product_qty); //Multiply item quantity * price
  $total    = ($total + $subtotal); //Add up to total price
 }
 
 $grand_total = $total + $shipping_cost; //grand total
 
 foreach($taxes as $key => $value){ //list and calculate all taxes in array
   $tax_amount  = round($total * ($value / 100));
   $tax_item[$key] = $tax_amount;
   $grand_total  = $grand_total + $tax_amount; 
 }
 
 foreach($tax_item as $key => $value){ //taxes List
  $list_tax .= $key. ' '. $currency. sprintf("%01.2f", $value).'<br />';
 }
 
 $shipping_cost = ($shipping_cost)?'Shipping Cost : '.$currency. sprintf("%01.2f", $shipping_cost).'<br />':'';
 
 //Print Shipping, VAT and Total
 $cart_box .= "<li class=\"view-cart-total\">$shipping_cost  $list_tax <hr>Payable Amount : $currency ".sprintf("%01.2f", $grand_total)."</li>";
 $cart_box .= "</ul>";
 
 echo $cart_box;
}else{
 echo "Your Cart is empty";
}
?>
</body>
</html>
Add CSS style
body {
 background-color: #F9F9F9;
 font-family: Georgia, "Times New Roman", Times, serif;
}
ul.products-wrp {
 list-style: none;
 padding: 0;
 max-width: 650px;
 margin-left: auto;
 margin-right: auto;  
 color: #777;  
 text-align: center;
}
ul.products-wrp li{
 display: inline-block;
 border: 1px solid #ECECEC;
 margin: 5px;
 background: #fff;
 text-align: center;
}
ul.products-wrp li h4{
 margin: 0;
 padding: 15px 5px 5px 5px;
 text-align: center;
 border-bottom: 1px solid #FAFAFA;
}
ul.products-wrp li .item-box{
 border: 1px solid #EAEAEA;
 background: #F9F9F9;
 margin: 5px;
 padding: 5px;
 text-align: left;
}
ul.products-wrp li .item-box div{
 margin-bottom:5px;
}
ul.products-wrp li .item-box button{
 margin-left: 5px;
 background: #FA1C5F;
 border: none;
 padding: 3px 8px 3px 8px;
 color: #fff;
}
ul.products-wrp li .item-box button[disabled=disabled]{
 background: #FC84A8;
}

.cart-box {
 display: block;
 width: 30px;
 background: rgba(219, 0, 33, 1) url(../images/cart-icon.png) no-repeat 20px 5px;
 padding: 4px 8px 4px 8px;
 border-radius: 30px;
 color: #fff;
 font-family: Arial;
 font-size: 16px;
 text-decoration: none;
 box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.32);
 margin-right: auto;
 margin-left: auto;
 font-weight: bold;
}
.cart-box:hover{
 background: #FA1C5F url(../images/cart-icon.png) no-repeat 20px 5px;
}
.shopping-cart-box{ 
 position: absolute;
    left:0;
    right:0;
    margin-left:auto;
    margin-right:auto;
 max-width: 450px;
 color: #FFD5D5;
 background: #FA1C5F;
 border-radius: 4px;
 padding: 10px;
 font: small Verdana, Geneva, sans-serif;  
 margin-top: 10px;
 display:none;
}
.shopping-cart-box a{
 color: #FFD5D5;
 text-decoration:none;
}
.shopping-cart-box:after {
 content: '';
 position: absolute;
 bottom: 100%;
 left: 50%;
 margin-left: -8px;
 width: 0; height: 0;
 border-bottom: 8px solid rgba(255, 0, 97, 1);
 border-right: 8px solid transparent;
 border-left: 8px solid transparent;
}
.shopping-cart-box ul.cart-products-loaded{
 margin: 0;
 padding: 0;
 list-style: none;
}
.shopping-cart-box .close-shopping-cart-box{
  float: right;
}
#shopping-cart-results ul.cart-products-loaded li{
 background: #ED0C50;
 margin-bottom: 1px;
 padding: 6px 4px 6px 10px;
}
.shopping-cart-box .remove-item{
 float:right;
 text-decoration:none;
}
.shopping-cart-box .cart-products-total{
 font-weight: bold;
 text-align: right;
 padding: 5px 0px 0px 5px;
}
.shopping-cart-box h3{
 margin: 0;
 padding: 0px 0px 5px 0px;
}

ul.view-cart {
  width: 600px;
  margin-left: auto;
  margin-right: auto;
  background: #fff;
  padding: 15px 15px 15px 25px;
  list-style: none;
}

ul.view-cart {
  width: 600px;
  margin-left: auto;
  margin-right: auto;
  background: #fff;
  padding: 15px 15px 15px 25px;
  list-style: none;
  border: 1px solid #ECECEC;
  border-radius: 4px;
}
ul.view-cart li span{
    float: right;
}
ul.view-cart li.view-cart-total{
  border-top: 1px solid #ddd;
  padding-top: 5px;
  margin-top: 5px;
  text-align: right;
}
hr{
 border: 0;
    height: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}

Tuesday, May 12, 2015

CSS & HTML Mac Terminal shell look-alike

CSS and HTML Mac Terminal shell look-alike

<style>
.shell-wrap {
  width: 500px;
  margin: 100px auto 0 auto;
  box-shadow: 0 0 30px rgba(0,0,0,0.4);
 
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
}
 
.shell-top-bar {
  text-align: center;
  color: #525252;
  padding: 5px 0;
  margin: 0;
  text-shadow: 1px 1px 0 rgba(255,255,255,0.5);
  font-size: 0.85em;
  border: 1px solid #CCCCCC;
  border-bottom: none;
 
  -webkit-border-top-left-radius: 3px;
  -webkit-border-top-right-radius: 3px;
  -moz-border-radius-topleft: 3px;
  -moz-border-radius-topright: 3px;
  border-top-left-radius: 3px;
  border-top-right-radius: 3px;
 
  background: #f7f7f7; /* Old browsers */
  background: -moz-linear-gradient(top,  #f7f7f7 0%, #B8B8B8 100%); /* FF3.6+ */
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f7f7f7), color-stop(100%,#B8B8B8)); /* Chrome,Safari4+ */
  background: -webkit-linear-gradient(top,  #f7f7f7 0%,#B8B8B8 100%); /* Chrome10+,Safari5.1+ */
  background: -o-linear-gradient(top,  #f7f7f7 0%,#B8B8B8 100%); /* Opera 11.10+ */
  background: -ms-linear-gradient(top,  #f7f7f7 0%,#B8B8B8 100%); /* IE10+ */
  background: linear-gradient(to bottom,  #f7f7f7 0%,#B8B8B8 100%); /* W3C */
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f7f7f7', endColorstr='#B8B8B8',GradientType=0 ); /* IE6-9 */
}
.shell-body {
  margin: 0;
  padding: 5px;
  list-style: none;
  background: #141414;
  color: #45D40C;
  font: 0.8em 'Andale Mono', Consolas, 'Courier New';
  line-height: 1.6em;
 
  -webkit-border-bottom-right-radius: 3px;
  -webkit-border-bottom-left-radius: 3px;
  -moz-border-radius-bottomright: 3px;
  -moz-border-radius-bottomleft: 3px;
  border-bottom-right-radius: 3px;
  border-bottom-left-radius: 3px;
}
 
.shell-body li:before {
  content: '$';
  position: absolute;
  left: 0;
  top: 0;
}
.shell-body li {
  word-wrap: break-word;
  position: relative;
  padding: 0 0 0 15px;
}
</style>
<div class="shell-wrap">
  <p class="shell-top-bar">/Users/ednalan/Documents/websites/</p>
  <ul class="shell-body">
    <li>cd /Users/ednalan/Documents/websites/tutorial101.blogspot.com/git/css-shell/demo/</li>
    <li>cd ../../../../</li>
    <li>pwd</li>
    <li>/Users/ednalan/Documents/websites/</li>
  </ul>
</div>

Sunday, February 8, 2015

Dropdown with dynamic content (Ajax/CodeIgniter)

Dropdown with dynamic content (Ajax/CodeIgniter)  

Controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Ajax_sample extends CI_Controller {
/* file: application/controllers/ajax_sample.php */

    function index(){
        $data = array();

        $data['arr_field1'] = array(
            1 => 'option 1',
            2 => 'option 2',
            3 => 'option 3',
        );

        $this->load->helper('form');

        $this->load->view('sample_dropdown', $data);
    }

    function get_dropdown_values($filter){

        $this->load->model('test_model');

        $result = $this->test_model->get_options($filter);

        $this->load->helper('form');

        echo form_dropdown('field2', $result, NULL, 'id="field2"');
    }
}
Model:
<?php
class Test_model extends CI_Model {
/* file: application/models/test_model.php */

    function get_options($filter=''){

        switch($filter){
            case 1:
                $arr = array('option A', 'option B', 'option C');
            break;
            case 2:
                $arr = array('option D', 'option E', 'option F');
            break;
            case 3:
                $arr = array('option G', 'option H', 'option I');
            break;
            default: $arr = array('option Z');
        }

        return $arr;
    }
}
View:
<?php

/* file: application/views/sample_dropdown.php */


    echo form_open('insert');

        echo form_dropdown('field1', $arr_field1, NULL, 'id="field1" onchange="load_dropdown_content($(\'#field2\'), this.value)"');

        echo form_dropdown('field2', array('0' => '...'), NULL, 'id="field2"');

    echo form_close();

?>
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">

function load_dropdown_content(field_dropdown, selected_value){
    var result = $.ajax({
        'url' : '<?php echo site_url('ajax_sample/get_dropdown_values'); ?>/' + selected_value,
        'async' : false
    }).responseText;
    field_dropdown.replaceWith(result);
}

</script>
URL : http://localhost/codeIgniter_3_1_10/ajax_sample

Wednesday, November 26, 2014

How to limit the number of selected checkboxes

How to limit the number of selected checkboxes

 
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>How to limit the number of selected checkboxes</title>
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
var limit = 3;
$('input.single-checkbox').on('change', function(evt) {
   if($(this).siblings(':checked').length >= limit) {
       this.checked = false;
   }
});
});//]]> 

//option 2
//$(window).load(function(){
//$('input[type=checkbox]').change(function(e){
//  if ($('input[type=checkbox]:checked').length > 3) {
//        $(this).prop('checked', false)
//        alert("allowed only 3");
//   }
//})
//});
 
</script>
</head>
<body>
         <div class="pricing-levels-3">
          <p><strong>Which level would you like? (Select 3 Levels)</strong></p>
          <input class="single-checkbox"type="checkbox" name="vehicle" value="Bike">Level 1<br>
          <input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 2<br>
          <input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 3<br>
          <input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 4<br>
          <input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 5<br>
          <input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 6<br>
          <input class="single-checkbox" type="checkbox" name="vehicle" value="Bike">Level 7<br>
        </div>
  
</body>
</html>

Sunday, November 23, 2014

How to Get Element id Using Jquery

How to Get Element id Using Jquery 

 
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
 <head>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
 <script type="text/javascript"> 
  $(document).ready(function () {
   $('.test').click(function() { 
     alert('' + $(this).attr('id'));
   });
  });  
 </script> 
 </head>
 <body>
  <input type="button" value="Button A" class="test" id="buttonA"> 
  <input type="button" value="Button B" class="test" id="buttonB">
 </body>
</html>

Jquery .first() and .last() Function Examples

Jquery .first() and .last() Function Examples
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <script>
   $(document).ready(function() { 
 
 $("#first").click(function(){       
  $("li").first().css("background-color",'#DD4B39');      
 });
 
 $("#last").click(function(){         
  $("li").last().css("background-color",'#DD4B39');
 });
 
   });
  </script>
   <div>
  <ul>
   <li>First Element</li>
   <li>Second Element</li>
   <li>Third Element</li>
   <li>Forth Element</li>
   <li>.....</li>  
   <li>.....</li>
   <li>Last Element</li>
  </ul>
 </div>
 </div>
  <button id="first" class="btn">First</button>  
  <button id="last" class="btn">Last</button>  

Related Post