Monday, December 22, 2008

Free Programming Q & A

I found a site that might be useful for all of you, Stack Overflow. It is a programming Q & A site that's free. Free to ask questions, free to answer questions, free to read, free to index, built with plain old HTML, no fake rot13 text on the home page, no scammy google-cloaking tactics, no salespeople. You can register if you want to collect karma and win valuable flair that will appear next to your name, but otherwise, it's just free. And fast. Very, very fast.

Stack Overflow is collaboratively built and maintained by your fellow programmers. Once the system learns to trust you, you'll be able to edit anything, much like Wikipedia. With your help, we can build good answers to every imaginable programming question together. No matter what programming language you use, or what operating system you call home -- better programming is our goal.

Sunday, December 21, 2008

How do you dynamically create a radio button in Javascript that works in all browsers?

Well, another bug from IE is the createElement() method. Unlike other browsers, it works weirdly by setting the default input "type" attribute to "text". Thus, you cannot change the "type" attribute to other value beside "text". Have a look on the documentation of this method from msdn microsoft.
Try the following code in IE by yourself, you might end up with the weird behavior on IE.


   var radio = document.createElement("input");
   radio.setAttribute("type", "radio");
   radio.setAttribute("name", "test_1");
   radio.setAttribute("value", "yes, it doesn't work!");
   radio.setAttribute("checked", "checked");


To solve this this problem, you need to pass the entire html code of element you want to create to createElement() method.


   var radio = document.createElement("<INPUT TYPE='RADIO' NAME='RADIOTEST' VALUE='First Choice'>");


The following code I quote from http://stackoverflow.com/questions/118693/how-do-you-dynamically-create-a-radio-button-in-javascript-that-works-in-all-br, and it works across all browsers.


   function createRadioElement( name, checked ) {
   var radioInput;
      try {
         var radioHtml = '<input type="radio" name="' + name + '"';
         if ( checked ) {
            radioHtml += ' checked="checked"';
         }
         radioHtml += '/>';
         radioInput = document.createElement(radioHtml);
      } catch( err ) {
         radioInput = document.createElement('input');
         radioInput.setAttribute('type', 'radio');
         radioInput.setAttribute('name', name);
         if ( checked ) {
            radioInput.setAttribute('checked', 'checked');
         }
      }

      return radioInput;
   }


Here are some other references:
http://www.quirksmode.org/bugreports/archives/2005/10/Radios_name_attribute_doesnt_work_when_using_appen.html
http://cf-bill.blogspot.com/2006/03/another-ie-gotcha-dynamiclly-created.html

Friday, December 19, 2008

JavaScript Frameworks

I have read one page, the comparison of javascript frameworks. It is good to know benefits, drawbacks, and limitations that each brought us back. From my personal experience:

1. MooTools is a compact framework, but it is suitable small web applications. One of the bad things I hate this framework is that it overrides the core javascript object. Even Dom objects has been overridden by MooTools. It has get() method and some other methods.

2. YUI has very bad documentation, but has lots of live functional examples. It has lots of properties, methods, and events. It is hard for the newbies to find a properties he need because the documentation just you do and you get it. It doesn't tell why and how this framework works. Sometimes I need to hook through the code. One the best things of YUI is has good configurator and it is modulus. You can take some functionalities off that are not useful in your web application. It also supports Back button support when you use Ajax Request.

3. ExtJS has two types of licenses: Commercial and GPL. It is good this framework if you build a single web application because it has many web controls look like windows controls. It has a very good documentation in air application and html pages. It has more features than YUI.

4. jQuery is a great JavaScript framework. It has great documentation and let you write less and do more. The size is also small enough. Actually, I like this framework.

5. Prototype & script.aculo.us. I used to work with this. Well, I think using jQuery is better than this.

http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks

Subscribe in a Reader