Hide or show element if checkbox input is checked

Posted by & filed under Website Development.

For example, if you wish to hide or show a textbox based on if a checkbox is selected: HTML: <input id=”showTextbox” type=”checkbox” /> <textarea id=”textbox”></textarea> JS if($(“#showTextbox”).is(‘:checked’)) $(“#textbox”).show(); // checked else $(“#textbox”).hide(); // unchecked

Change your cursor or pointer to a hand on hover with css

Posted by & filed under CSS.

Sometimes when I create a link, the cursor doesn’t change to a hand to help the user understand they can click on element. Thus, its helpful to have the cursor change to a hand on hover. No need for javascript or jquery here, you can easily implement the effect with CSS. The CSS .myElement:hover {… Read more »

Convert JSON Array to PHP Array

Posted by & filed under JSON, PHP.

To convert a JSON array into a PHP array, use the following script: <?php $json = file_get_contents(‘json/yourscript.json’); // Get the JSON data $phpObj = json_decode($json,true); // Convert to PHP Object print_r($phpObj); // Convert to PHP Array ?> file_get_contents(‘json/yourscript.json’); Allows you to get the JSON data easily. json_decode($json,true); Is a PHP function that converts your JSON… Read more »

HTML5 Quickstart Template – Mobile Viewport, CSS3, Google Font, Latest jQuery – All Ready

Posted by & filed under HTML, Javascript, jQuery, Website Development.

Whenever I want to quickly make a webpage, I don’t want to have to build the whole page everytime. Here is my starter code for an HTML5 page. The key points are : HTML5 Doctype – Ready Viewport and Mobile – Ready Title tags, Character Set, Keyword and Description Meta, Favicon, Stylesheet tags – Ready… Read more »

How to get a substring of Chinese or Japanese text without cutting off characters in PHP?

Posted by & filed under Website Development.

I used to try to get substrings of Chinese text and would get partial characters than came out as strange diamonds or squares…. until I found the mb_strcut() function! When using PHP, avoid using the substr() function, as it will often cut off Chinese and Japanese characters. For example: $text = ‘拿小锤锤的那个人好可爱的说,哈哈哈,生活太有爱了,加油加油了’; echo substr($text, 0,… Read more »

Get only the Domain Name from HTTP_REFERRER in PHP

Posted by & filed under PHP.

$_SERVER[‘HTTP_REFERER’] gives you the URL from where the user came, which is the user’s previous page (whatever page that would appear if the user clicked “Back” in their browser) But $_SERVER[‘HTTP_REFERER’]  gives you the complete URL, something like this : driverstest.info/test/quiz.php?quizgroup=7 If you just want get the domain name .i.e. driverstest.info from the full URL, then you can… Read more »

Convert Month Numbers to Month Names in PHP

Posted by & filed under PHP.

Here is a lovely bit of code to help you convert months in numbers to proper names! <?php $monthNum = 11; $monthName = date(“F”, mktime(0, 0, 0, $monthNum, 10)); echo $monthName; // Outputs: November ?>

Force links to open in a new tab, not a new window

Posted by & filed under CSS, HTML.

Yes it is possible with CSS to have links open in new tabs or new windows. I discovered this issue when testing target=”_blank” in IE9/IE10 versus Chrome. <a href=”[yourlink]” target=”_blank” style=”target-new: tab;”>GetPowers</a> Or you could put it in the header as: <html> <head> <style> a { target-new:tab; } </style> </head> <body>  There are some options… Read more »