Promises with jQuery

Promises with jQuery

Promises are starting to change the way we write asynchronous JavaScript. They allow us to write clearer, shorter callbacks and to separate application logic from DOM interaction.

jQuery’s implementation of the Promise pattern (introduced in version 1.5) centres around the Deferred object , the predominate use of which is to attach success and failure callbacks to AJAX requests.

Read more…

Simple AJAX Unit Converter

unit_converter

I’ve been doing quite a bit with jQuery and AJAX as of late and have not only been impressed at the ease of implementation, but also the snappy and responsive feel that it brings to your web apps.

To demonstrate this I’m going to show you how to make a simple unit converter, which will allow you to convert units of digital storage without having to make a single page refresh.

Here’s a demo of what we’ll end up with.

Read more…

How to tell if a form has been submitted using PHP

send_button_with_pointer

Consider this scenario:

You have a form which submits to itself (e.g. a simple contact form). The first time it loads you don’t want to do anything other that render the form.

However, when a user hits “Submit”, you want to process whatever data you have received, then re-render the form, including (for example) error messages where appropriate.

Read more…

How to detect a touch device using JavaScript

How to detect a touch device using JavaScript

A while back I had to make a navigation menu which played a sound when you moused over the various menu points.

The problem was, that this feature didn’t play nicely with touch devices, as they don’t really have a concept of hover.

What happened instead was that the sound would play when the user selected one of the menu points, but would get cut off as the new page loaded – eurgh!

Read more…

Sliding panels with jQuery

jQuery_coolness

Sliding panels are cool! jQuery is cool! Who doesn’t love sliding panels and jQuery??

This tutorial aims to show you how to build a menu, where the various items respond to a user click by sliding a panel into view containing relevant content.

Here’s a demo of what we’ll end up with.

Read more…

Simple JavaScript debugging with Chrome’s console

chrome_console

All to often of late, I have seen people having trouble trying to debug some JavaScript or other.

Some were stumped by the white screen of death which confronted them the minute their script failed silently, whilst others were trying to debug their program using an alert dialogue box (a truly tedious process).

Well, good news it at hand. There is another, more efficient way to do things – with the console. Read more…

PHP – header(‘Location: …’) not working in MAMP

PHP – header(‘Location: …’) not working in MAMP

Recently, I was trying to help someone build a simple contact form in PHP.

This person was running everything locally in a MAMP server (Macintosh, Apache, Mysql and PHP) and everything was going swimmingly until we ran into a strange issue: PHP’s header('Location: ...') wasn’t working as expected. In fact, to be fair, it wasn’t working at all.

This is how we solved the problem.

Read more…

Display your WordPress contact form in a Lightbox

Display your WordPress contact form in a Lightbox

Recently, a client asked me to have their contact form display in a Lightbox (as opposed to on a separate page). I happily implemented this for them and the end result looked pretty snazzy, so I thought I’d write up how I did it.

Read more…

Using cookies with jQuery to make a simple style switcher

Cookies with jQuery

Short for HyperText Transfer Protocol, HTTP is the underlying protocol of the World Wide Web. It is used when a browser requests a web page from a server and it is used when the server responds to the browser’s request. HTTP is great, but it is also stateless, which means that once a server has sent a page to a browser, it forgets having done so straight away. This can be a problem, for example, if a user has identified themselves in order to access protected pages, or if a user wants to customize some aspect of a website, as the server simply cannot remember a thing about it!

Sounds like a job for cookies!

Read more…

How to make a simple visitor counter using PHP

Total Visitors: 00000

Imagine you want a visitor counter on your homepage. Sure, there are plenty of free ones out there, but I’m never happy about embedding third party code in my website, and besides wouldn’t it be more fun to make your own?

Of course it would!

Read more…

Older Entries Arrow pointing to the right