June 19 2016

Javascript convert MSAccess color code to Hex color code

Tagged Under : ,

javascript
Because CSS not support MSAccess color code. If want use the MSAccess color code as color display on web. We need change the code to Hexadecimal Code.

May 16 2016

MySQL week of the month

Tagged Under : ,

MySQL
Normally if want display week of certain of the month, we can using WEEK() function. But WEEK() function only return you week of the year.

But now, we want display WEEK of the month no week of the year. that means first, second, third, fourth and fifth week of the month.

Below example is the SQL to display the week number of the month:
SELECT (WEEK(created_date,5) - WEEK(DATE_SUB(created_date, INTERVAL DAYOFMONTH(created_date)-1 DAY),5)+1) as week
The created_date column must be DATE or DATETIME type.

April 09 2016

CSS last float left full width

Tagged Under :

css3
I think some of the people facing some problem with me. How to set last float left to 100 percent or full width in div.

At below, I provide some example how to solve the problem. It not prefect, but work for me.

Example:
The example i give is 3 div in 1 row.

March 25 2016

Yii2 always load bootstrap.js

Tagged Under :

Yii
Normally on Yii2 wouldn’t always load the bootstrap.js on our Web App, only when you use js dependent bootstrap widgets such as yii\bootstrap\Modal and etc.

You need add some code on the framework to always load the bootstrap.js on the Web App.
Open the file on the following directory:

February 16 2016

WordPress Header error wp-includes/pluggable.php

Tagged Under : ,

Wordpress
When using wp_redirect() you will facing Header error “PHP Warning: Cannot modify header information – headers already sent by …… wp-includes/pluggable.php on line 1228”

To solve this problem you need to change the PHP.ini value. In PHP.ini find

February 16 2016

WordPress Ajax Example

Tagged Under : , ,

Wordpress
Below is the basic example of how to use AJAX in WordPress. It show you how to using javascript pass the variable to PHP function and then return back to javascript.

Javascript
var ajaxurl = '<?php echo admin_url() ?>admin-ajax.php';
jQuery(document).ready(function () {
	jQuery.ajax({
		url: ajaxurl,
		data: {
			//This action must same with the PHP function name
			"action": "ajax_request",
			"params": "wordpress ajax"
		},
		success:function(data) {
			//This is the result return from PHP function
			console.log(data);
		},
		error: function(errorThrown){
			//This is the error return
			console.log(errorThrown);
		}
	});
});

February 16 2016

Jquery only allow numeric (0-9) in HTML inputbox

Tagged Under :

jquery

Below is the function I use to only number, delete, backspace and tap are allow.
$(document).on("keydown", "#number", function(e) {
	var key = e.charCode || e.keyCode || 0;
	
	if (key == 8 || key == 9 || key == 13 || key == 46 || key == 110 || key == 190 || (key >= 35 && key <= 40) ||(key >= 48 && key <= 57) || (key >= 96 && key <= 105)) {
		return;
	} else {
		return false;
	}
});

December 02 2015

Yii2 cactiveform client validation not working with fancybox ajax

Tagged Under :

Yii
If using fancybox ajax display the Yii2 cactiveform you will found that the client validation are not working.

Its due to the form ID was invalid or duplicated in same page. what you need to do is assign a new form id inside cactiveform.

Example
$form = ActiveForm::begin([
  'enableClientValidation' => true,
  'id' => 'new_form_id'
]);

December 02 2015

Yii2 gridview column pass an array as param

Tagged Under :

Yii
In Yii2 now you are allow pass an array as param to gridview column for display the data. Below is the example how to pass array to gridview column.

Exmaple:
The $status is an array and $data is the model results.
'content' => function($data) use ($status) {
  return (isset($status[$data->status]) ? $status[$data->status] : $data->status);
},

Complete Example:
 $model->search(),
  'filterModel' => $model,
  'showOnEmpty'=>true,
  'columns' => [
    'id',
    'name',
    [
      'attribute' => 'status',
      'filter' => $status,
      'content' => function($data) use ($status) {
        return (isset($status[$data->status]) ? $status[$data->status] : $data->status);
      },
    ],
  ],
]); ?>

October 22 2015

CSS set opacity background color only not text and image

Tagged Under :

css3
To set the opacity level for a <div> element as the below example:
div {
    opacity: 0.5;
}
But the following example will let the content inside the <div> become transparent as well.

Instead of using “opacity” to set transparent background-color. You can try using “rgba” function as below.
background-color: rgba(255, 0, 0, 0.5);
Now, only the background is transparent.