One technique I’m seeing more and more these days (CNNSI.com, for example) is AJAX recording of selected text. It makes sense — if you detect users selecting the terms over and over again, you can probably assume your visitors are searching that term on Google, Yahoo, etc. I’ve duplicated this functionality using my favorite javascript library, MooTools, and another javascript library, jQuery.
AJAX Archives
Record Text Selections Using MooTools or jQuery AJAX
Form Element AJAX Spinner Attachment Using jQuery
Yesterday I showed you how to attach an AJAX spinner next to a form element using my beloved MooTools. Today I’ll show you how to implement that same functionality using jQuery.
The XHTML
<select class="ajax"> <option value="">-- Select a Site--</option> <option value="David Walsh Blog">David Walsh Blog</option> <option value="Script & Style">Script & Style</option> <option value="Band Website Template">Band Website Template</option> </select> <br /><br /> <input type="text" id="my-text" class="ajax" />
Elements with the “ajax” CSS class will be our target.
Form Element AJAX Spinner Attachment Using MooTools
Many times you’ll see a form dynamically change available values based on the value of a form field. For example, a “State” field will change based on which Country a user selects. What annoys me about these forms is that they’ll often do an AJAX request to grab the states but wont show any indicator to the user that something is happening. We’re going to use MooTools to add an AJAX spinner image next to form fields that perform such AJAX requests.
Remotely Download Google AJAX Libraries Using PHP
I don’t know how to use all of the javascript libraries but perusing their code is interesting. If I’m looking to code something I’ll look at how each of the other libraries accomplishes the task. The problem is that you need to go out and download each one. And of course they’re all on different development schedules so you’d also need to make sure to grab the latest version of the library. Instead of manually accomplishing that task, I’ve chosen create a script that does all of that for me.
Create an “Add to TextMate” Widget Using MooTools

If a sword is a soldier’s best friend, the best friend of a programmer is a his text editor. TextMate has been my text editor of choice and a big reason for that is the ability to add snippets for quick use later. Since I provide a lot of snippets on my blog and many of my readers use TextMate, I’ve created an “Add To TextMate” widget using a mixture of MooTools, AJAX, CSS, and PHP.
The CSS
.tmbundle { display:block; float:left; background:url('textmate-icon.png') center no-repeat #eee; border:1px solid #ccc; color:#000; font-size:14px; font-weight:bold; text-decoration:none; width:26px; height:26px; text-indent:-9999px; border:1px solid #ccc; -moz-border-radius:3px; -webkit-border-radius:3px; }
The only CSS code needed is the “Add to TextMate” link. Style as you desire.