Tuesday 18 October 2016

yii2 - How to use registerMetatag in Yii 2

To define some meta tag through the registerMetaTag method, use the following code in your controller:


public function actionIndex()
{
    \Yii::$app->view->registerMetaTag([
        'name' => 'description',
        'content' => 'Description of the page...'
    ]);
    return $this->render('index');
}
and this markup in the layout:
<head>
    <?php $this->head() ?>
</head>
yii2 - How to use registerMetatag in Yii 2

Sunday 16 October 2016

How to Create Accordion with Bootstrap collapse

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Example of Bootstrap 3 Accordion</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <style type="text/css">
        .bs-example {
            margin: 20px;
        }
    </style>
</head>

<body>
    <div class="bs-example">
        <div class="panel-group" id="accordion">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">1. What is HTML?</a>
                </h4>
                </div>
                <div id="collapseOne" class="panel-collapse collapse in">
                    <div class="panel-body">
                        <p>HTML stands for HyperText Markup Language. HTML is the main markup language for describing the structure of Web pages. <a href="http://www.tutorialrepublic.com/html-tutorial/" target="_blank">Learn more.</a></p>
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">2. What is Bootstrap?</a>
                </h4>
                </div>
                <div id="collapseTwo" class="panel-collapse collapse">
                    <div class="panel-body">
                        <p>Bootstrap is a powerful front-end framework for faster and easier web development. It is a collection of CSS and HTML conventions. <a href="http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/" target="_blank">Learn more.</a></p>
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">3. What is CSS?</a>
                </h4>
                </div>
                <div id="collapseThree" class="panel-collapse collapse">
                    <div class="panel-body">
                        <p>CSS stands for Cascading Style Sheet. CSS allows you to specify various style properties for a given HTML element such as colors, backgrounds, fonts etc. <a href="http://www.tutorialrepublic.com/css-tutorial/" target="_blank">Learn more.</a></p>
                    </div>
                </div>
            </div>
        </div>    
    </div>
</body>
</html>

How to Create Accordion with Bootstrap collapse 

How to Auto Resize a textarea with jQuery

<html>
  <head>
    <title>Auto Resize textarea with jQuery</title>
    <style>
      .autotextarea{
        min-height: 20px;
        overflow: hidden;
        resize: none;
        padding: 4px;
        font-size: 14px;
        border: 1px solid #000;
      }
    </style>
    <script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  </head>
  <body>
    <textarea class="autotextarea" placeholder="Enter Text"></textarea>
<script>
$('.autotextarea').on('keyup',function(){
$(this).css('height','auto');
$(this).height(this.scrollHeight);
});
</script>
  </body>
</html>


How to Auto Resize a textarea with jQuery

Wednesday 12 October 2016

Validate (Check) HTML Select option DropDownList using JavaScript and jQuery

JavaScript :

Select List:

<select id="ddlList">
    <option value=""></option>
    <option value="1">List 1</option>
    <option value="2">List 2</option>
    <option value="3">List 3</option>
</select>
<input type="submit" value="Validate" onclick="return Validate()" />
<script type="text/javascript">
    function Validate() {
        var ddlList= document.getElementById("ddlList");
        if (ddlList.value == "") {
            //If the "Please Select" option is selected display error.
            alert("Please select an option!");
            return false;
        }
        return true;
    }
</script>


jQuery :

Select List:

<select id="ddlList">
    <option value=""></option>
    <option value="1">List 1</option>
    <option value="2">List 2</option>
    <option value="3">List 3</option>
</select>
<input type="submit" id="btnSubmit" value="Validate" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#btnSubmit").click(function () {
            var ddlList= $("#ddlList");
            if (ddlList.val() == "") {
                //If the "Please Select" option is selected display error.
                alert("Please select an option!");
                return false;
            }
            return true;
        });
    });
</script>


Validate (Check) HTML Select option  DropDownList using JavaScript and jQuery

Download a div in a HTML page as pdf using javascript

You can do it using jsPDF

OR

<script type="text/javascript" src="https://cdn.jsdelivr.net/jspdf/1.3.2/jspdf.min.js"></script>

HTML:
<div id="content">
     <h3>Hello, this is a H3 tag</h3>

    <p>a pararaph</p>
</div>
<div id="editor"></div>
<button id="cmd">generate PDF</button>
JavaScript:
var doc = new jsPDF();
var specialElementHandlers = {
    '#editor': function (element, renderer) {
        return true;
    }
};

$('#cmd').click(function () {
    doc.fromHTML($('#content').html(), 15, 15, {
        'width': 170,
            'elementHandlers': specialElementHandlers
    });
    doc.save('sample-file.pdf');
});



OUTPUT EXAMPLE

Hemant Vishwakarma - Programming Blog, Tutorials, jQuery, Ajax, PHP, MySQL Code

Software & Website Developer Expert in Core PHP, Yii, Wordpress, Codeignter,
Laravel, Bootstrap, javaScript, CSS,Ajax etc. Web design / Development






Download a div in a HTML page as pdf using javascript