jQuery handle null value in PHP variable or array

August 6, 2014

Handling php array or variable inside javascript directly using json_encode, will result some value null. To check null using jquery in this case:

jQuery select list set selected using php variable

August 6, 2014

Using jQuery to set the selected element of the select control to be the item with the text description. Value from php.

jQuery Datepicker does not work in dynamic element

August 5, 2014

This always happen when bind the event initially, the new field doesn’t exist. A better way is initialize the datepicker for the field when create the element. Example after an AJAX call to build the fields:

PHP check a string is an email address format

July 29, 2014

With PHP v5.2.0 or greater, you may use regular expressions.

jQuery add attribute to html element and remove

July 25, 2014

You can add attributes using attr like below: To remove: However, for DOM properties like checked, disabled and readonly, the proper way to do this (as of JQuery 1.6) is to use prop. To remove:

jQuery checkbox checked state changed event

July 25, 2014

Bind to the change event instead of click. However, you will probably still need to check whether or not the checkbox is checked: Example below shows and hide a div when checkbox checked or unchecked

PHP replace spaces in urls image name

July 21, 2014

Looking to replace all instances of spaces in urls with %20? No need for a regex. Use rawurlencode() instead urlencode() for this purpose. Example: urlencode($img) will result It will not change to %20. But with rawurlencode($img), it produce Another way of doing it is using str_replace

Jquery read element attribute id with square brackets [ ]

July 16, 2014

To use any of the meta-characters ( such as !”#$%&’()*+,./:;?@[\]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\. For example, an element with id=”foo.bar”, can use the selector $(“#foo\\.bar”). Example: Reference: Special Characters In Selectors

PHP sort multidimensional Array by specific key value

July 14, 2014

Try usort for multidimensional array sorting by specific key value inside each sub array. Example: The best way is: reference: http://stackoverflow.com/questions/2699086/sort-multidimensional-array-by-value-2

FUELPHP Form Checkbox checked

July 1, 2014

FuelPHP checkbox is not a nightmare if understand it’s parameters correctly. The syntax is checkbox($field, $value = null, $checked = null, $attributes = array()) To built form checkbox, simply do like below: Will output a checked checkbox: To uncheck the checkbox, changed the ‘checked’ value to empty ” or null