Tech Thought

Tech tips, hints, and general musings. PHP, Perl, Mysql, Javascript, AJAX, JSON, Linux, Mac OSX

Entries for the ‘Development’ Category

PDF Version of API Reference for Prototype.js

I use the prototype.js javascript framework daily and as a result having an update-to-date API reference is essential. Thankfully, you can view the entire API online at the prototype.js website in an easily accessible form. Personally I find PDFs a bit easier to manage for API references.    Josh Clarke at GlobalMoxie has put together [...]

Comments (1)

TortoiseSVN for Mac OS X: SCPlugin

I’ll admit I’m a recently reformed windows user, as I’ve really only been using a Mac for the part 8 months. One thing I really missed as a developer when switching to the Mac was a nice integrated SVN client like TortoiseSVN. Thankfully, there is SCPlugin – a Finder plugin for Mac OS X which [...]

Comments (1)

ModalBox: Modal Dialog Boxes Based on Prototype.js

If you’ve ever used the Sustainability Victoria calculator, Administered Joomla or poked someone on Facebook, then you might wonder how they create those nice modal dialog boxes that have replaced the ugly javascript confirm() in most modern web applications: Well, thanks to prototype.js and ModalBox now you can. ModalBox is a javascript library that helps [...]

Leave a Comment

How-To: Speed up page loading – compressed prototype.js

To help speed up the load time of your prototype.js and scriptaculous pages, you can now download fully compressed versions of all the required files from the ‘prototype-core’ group on google thanks to John David-Dalton (original post on Ajaxian): http://groups.google.com/group/prototype-core This reduces the size of prototype and scriptaculous to 64k total! Be sure to read [...]

Leave a Comment

Javascript OO: Scope of ‘this’ variable when using prototype.js

If you write a fair bit of OO javascript and also utilise AJAX through one of the many frameworks (I personally use prototype.js most of the time) you may have come across the following issue: var myobj = new Object(); myobj.Methods = { result: 0, callAjax: function() { new Ajax.Request(‘ajax.php’, { onComplete: function(transport) { this.result [...]

Comments (2)

How-To: Debugging Javascript in IE with Microsoft Script Debugger

Debugging javascript in IE is often like walking on a minefield with a blindfold on. You have no idea where you are when bombs go off. Thankfully, Microsoft provides a debugging tool called Microsoft Script Debugger which makes debugging javascript much easier. You can download the tool from here. Once installed you get a full [...]

Comments (1)

URL Encoding a string with javascript

The following javascript function returns a URL encoded string so that it is safe to use in URLs or as a GET request: function URLDecode (encodedString) { var output = encodedString; var binVal, thisString; var myregexp = /(%[^%]{2})/; while ((match = myregexp.exec(output)) != null && match.length > 1 && match[1] != ”) { binVal = [...]

Leave a Comment

SVN: Creating a new project using command line

I always forget the syntax for creating a new project using SVN via the command line. So here it is: svn import <directory> <repository path> -m “Initial checkin” Where the directory should contain the files you want to add to the repository, and the repository path should be something like: svn+ssh://evan@charzard/usr/local/svn/repository/trunk/1.0/<project name>

Leave a Comment

php $_SESSION variable doesn’t stay persistent

Recently I was creating a new website from scratch, which required authentication and the use of PHP’s sessions functionality. I used the session to store information which I needed to be persistent between pages: Page 1 Page 2 However page 2 would never display the user ID value. I couldn’t work out what was causing [...]

Leave a Comment

Typecasting Strings to Numbers in Javascript

If you are using the values on a page (e.g. the values of form elements) directly in mathematical formulas in javascript, you can have issues with ambiguity of types. For instance: var total = 0; total += document.myForm.element.value; // e.g. value = 5 alert(total); The above example can lead to a result of “05″ instead [...]

Comments (1)

Javascript validation of Email Address, Numeric Values and an Input Mask for Numbers Only

A couple of very simple yet handy routines for validation of form fields: Function to validate an email address (see original post): function ValidateEmail(email){ var emailReg = “^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$”; var regex = new RegExp(emailReg); return regex.test(email); } Function to validate a number: function ValidateNumber(num) { return num.match(/^\d+$/); } Input mask for a field to only accept [...]

Comments (2)

Creating Objects with Javascript

Recently I’ve started overhauling all our old javascript libraries to make them more object-based and easier to maintain. As a result, I’ve needed to get familiar with how to create objects and assign properties and methods. This is surprisingly easy in javascript: Creating an object (Constructor) with properties: function MyObject(param1, param2) { this.myProperty = param1; [...]

Leave a Comment

“Foreach” style loop syntax for Perl, Php and Javascript

I am always forgetting the syntax for foreach() loops in javascript. They actually don’t exist (not in their Perl or Php form anyway) and they differ in that they iterate over all the properties of an object, not an array. You can get some unexpected results if you aren’t careful. In perl you do the [...]

Comments (2)

Problem with PHP json_decode() and prototype.js .toJSON() function

I have been tearing my hair out trying to work out why PHP’s json_decode() function wouldn’t convert a JSON string sent via AJAX using the prototype.js .toJSON() function. I was sending the string: {\”Assembly_ID\”: 1} However json_decode() in php would return NULL. After some fiddling around, I determined that json_decode() doesn’t like the “\” characters. [...]

Comments (4)

Data::Dumper for PHP

Along the same lines of my previous post, I was looking for a PHP equivalent to Data::Dumper for Perl. Php has a builtin function called var_dump() which will give you some fairly ugly output about your array/hash/object, however I was looking for something a little more elegant.Thankfully the folks over at Pear have come up [...]

Comments (1)