jump to navigation

An ‘Only in Silicon Valley’ Wedding Registry – Bits Blog – NYTimes.com August 25, 2009

Posted by Chao in Uncategorized.
add a comment

Javascript: Textarea/text field with UI for limiting max characters August 12, 2009

Posted by Chao in Uncategorized.
add a comment

Want to build a Twitter clone? You’ll need a text field that limits text entry to 140 characters?

How ’bout one of those faddish question and answer sites (like alas our own failed) CoolQs? You’ll need the same widget that tells you how many characters you have left for your question.

You could use the MAXLENGTH or SIZE attributes for the <input> field. But that doesn’t provide the user with the instant feedback as to how many characters the user has left as the user types away.

Well, it’s your lucky day – I have just the widget for you if you use the Prototype library.

To turn any html text field or textarea, try


new TextLimiter<source elt>, <options>

e.g.

new TextLimiter 'whatsup', {limit:140}

<source elt> is the text field or textarea object you want add TextLimiter behaviors to. You can specify the DOM id or the javascript object, as per standard Prototype classes.

Optional options (is that redundant?) include:

  • statusElt: DOM element to provide feedback as user types. statusElt.show() is called when the user starts typing.
  • countElt: The DOM element usually within statusElt that is dynamically updated to show how many characters are left.
  • limit: the maximum number of characters allowed. Hard-coded default is 110.

Here’s the code:

var TextLimiter = Class.create();
TextLimiter.prototype = {
 initialize: function(textField, options) {
 //options: statusElt, countElt, limit
 this.textField = $(textField);
 this.options = Object.extend({limit:110}, options || {});
 var status = this.options.statusElt = $(this.options.statusElt);
 if (status) {status.hide();}
 this.options.countElt = $(this.options.countElt);
 this.textField.observe('keyup', this.keyUp.bindAsEventListener(this));
 this.textField.observe('focus', this.focus.bindAsEventListener(this));
 },
 focus: function() {
 if (this.options.statusElt) {this.options.statusElt.show();}
 },
 keyUp: function() {
 var field = this.textField;
 var limit = this.options.limit;
 if (field.value.length > limit) {
 field.value = field.value.substring(0, limit);
 } else if (this.options.countElt) {
 var total = limit - field.value.length;
 this.options.countElt.innerHTML = total;
 }
 }
};

The Netflix Maximalist August 12, 2009

Posted by Chao in Uncategorized.
add a comment

To all those avid netflix users (it’s a long story, but I’m now more a BlockBuster user), this is hiliarious:

The Netflix Zen Master « Joe Doliner.

It does sounds more like a Netflix Maximalist than a Zen Minimalist, nay?

Yay, Rails on Google App Engine August 6, 2009

Posted by Chao in Uncategorized.
add a comment

Postling: Etsy Founders Do Social Media for Small Business – ReadWriteEnterprise August 5, 2009

Posted by Chao in Uncategorized.
add a comment

Postling looks interesting as a way to manage all you social media – and not just for small businesses. I wonder if there should be a Free version, tho’?

Good Alan Kay quotes « Stever’s blog August 5, 2009

Posted by Chao in Uncategorized.
add a comment

Fascinating array of businesses reviewed in NYMag August 3, 2009

Posted by Chao in Uncategorized.
add a comment

How to Have an Overnight Internet Success Story August 3, 2009

Posted by Chao in Uncategorized.
add a comment

Wow, great article about the two main ways to succeed on the web today! Gabbay’s definition of a viral app (“one where each new user must involve friends to derive personal value from the service.”) is a useful one.

How to Have an Overnight Internet Success Story.

Styrofoam dome homes August 3, 2009

Posted by Chao in Uncategorized.
add a comment

A speculative feature list of Apple’s rumored table August 3, 2009

Posted by Chao in Uncategorized.
add a comment