11.4.09

jQuery

"Javascript needs to go and something new needs to replace it" this is what I said to anyone who talked about javascript. Though I knew the advantages of JavaScript I was always bugged by the simple mistakes we could make and get those ugly errors. We also had to write extensive code to implement some complex logic.

We started implementing jQuery today and I must say, I was totally blown off. Its such a simple solution and yet powerful that it knocks off all the issues/mistakes which a developer writing javascript would make.

Below is the link which I am using to learn jQuery. Start with the beginner examples and it should be easy from there.

Learning jQuery

I will try to post more on jQuery as and when I find something good to share.


6.4.09

Javascript to correct case for Name fields

Though this might be a simple script, I felt it always good to share a re-usable code

Text Entered - o'reAlly jack daniels mc donald
Changes to - O'Really Jack Daniels Mc Donald


function CorrectNamingCase(control) {
var pattern = /(\w)?(\w*)?(\W\w)?(\S*)/; // a letter, and then rest of word, special character word, none or more letters

var a = control.value.split(/\s+/g); // split the sentence into an array of words

for (i = 0; i < a.length; i++) {
var parts = a[i].match(pattern); // just a temp variable to store the fragments in.

var firstLetter = parts[1].toUpperCase();
var firstWord = parts[2].toLowerCase();
var specialWord = parts[3].toUpperCase();
var restOfWord = parts[4].toLowerCase();

a[i] = firstLetter + firstWord + specialWord + restOfWord; // re-assign it back to the array and move on
}
control.value = a.join(' '); // join it back together
}