<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8297537222156961313</id><updated>2011-11-27T15:57:32.166-08:00</updated><category term='XML'/><category term='Advertising'/><category term='Javascript'/><category term='HTML'/><category term='Google AdWords'/><title type='text'>Speaking in Javascript</title><subtitle type='html'>For those who love playing with JavaScript</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javascriptrev.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://javascriptrev.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Christian Amaonwu</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='20' height='32' src='http://3.bp.blogspot.com/_58l6ncjdQ6s/SYrBGt7YRBI/AAAAAAAAAA8/b6YZne8PnfE/S220/zala1.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8297537222156961313.post-7918151536739120740</id><published>2008-06-13T12:00:00.000-07:00</published><updated>2008-06-13T12:02:00.989-07:00</updated><title type='text'>Javascript and design patterns(100)</title><content type='html'>Javascript is one of the most popular and widely used languages in the world today.Because it is embedded in all modern browsers, t has an extraordinarily wide distribution. As a language, it is incredibly important in our daily lives, powering the websites that we go to and helping the web to present a rich interface. Why then do some still consider it to be a toy language, not worthy of the professional programmer? I think it is because people do not realize the full power of the language and how unique it is in the programming world today.Javascript is a very expressive language, with some features that are uncommon to the C family of languages. In this blog and subsequent ones , i will be looking at how the langauge allows you to accomplish the same task in a number of different ways and how you can take alternative approaches to object-oriented programming by using concepts from function programming.The truth is you can apply design pattern concepts in your Javascript programming. In a couple of articles that follows i will be discussing briefly the following design patterns as it concerns javascript with functional example to give you a concrete example of each of them:&lt;br /&gt;The Factory pattern&lt;br /&gt;The Bridge pattern&lt;br /&gt;The Composite pattern&lt;br /&gt;The Facade pattern&lt;br /&gt;The Adapter pattern&lt;br /&gt;The Decorator pattern&lt;br /&gt;The Flyweight pattern&lt;br /&gt;The Proxy pattern&lt;br /&gt;The Observer pattern&lt;br /&gt;The Command pattern&lt;br /&gt;The Chain of Responsibility pattern&lt;br /&gt;Keep a date with me while a take you through the world of javascript design patterns&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8297537222156961313-7918151536739120740?l=javascriptrev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javascriptrev.blogspot.com/feeds/7918151536739120740/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8297537222156961313&amp;postID=7918151536739120740' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default/7918151536739120740'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default/7918151536739120740'/><link rel='alternate' type='text/html' href='http://javascriptrev.blogspot.com/2008/06/javascript-and-design-patterns100_13.html' title='Javascript and design patterns(100)'/><author><name>Christian Amaonwu</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='20' height='32' src='http://3.bp.blogspot.com/_58l6ncjdQ6s/SYrBGt7YRBI/AAAAAAAAAA8/b6YZne8PnfE/S220/zala1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8297537222156961313.post-7980504746246102201</id><published>2008-06-13T10:10:00.000-07:00</published><updated>2008-06-13T11:50:13.692-07:00</updated><title type='text'>The Factory pattern (101)</title><content type='html'>The simplest way to create new objects is to use the &lt;strong&gt;new&lt;/strong&gt; keywords and a concreate class. The extra complexity of creating and maintaining a factory only makes sense in certian situations, which are outlined in this section.&lt;br /&gt;&lt;br /&gt;If you need to create objects with the same interface but different implementations, a factory method or a simple factory object can simplify the process of choosing which implementation is used. This can happen implicitly in Ajax request where the type of connection object created depends on factors such as the percieved bandwidth and network latency. In these situations, you usually have a number of classes that implement the same interface and can be treated identically. In Javascript this is the most common reason for using the factory pattern.&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Many Small Objects in one Large Object&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;A factory method can be useful for creating an object that encapsulates a lot of smaller objects. As an example , consider the constructor for a biycicle objects. A bicycle is comprised of many smaller subsystems;wheels, a frame, a drive train, brakes. If you do not want to tightly couple one of those subsystems to the lager object, but instead want to be able to choose one out many subsystems at run-time, a factory method is ideal. Using this technique, you could create all of the bicycles with a certain type of chain on one day, and change that type the next day if you find one that is better suited to yyour needs. Making this changes is easy because the bicycles do not depend on a specific type of chain in their constructor.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Example:(Ajax request Example)&lt;/strong&gt;&lt;br /&gt;A common task in any web page these days is to make an asynchronious request using Ajax. depending on the user's browser, you will have to instatiate one of several different classes in order to get an object that can be used to make a request. If you are making more than one  Ajax request in your code, it  makes sense to abstract this object creation code into a class and to create a wrapper for the different steps it takes to actually make the request. A simple factory works very well here to create an instant of either XMLHttpRequest or ActiveXObject, depending on the browser's capabilities:&lt;br /&gt;&lt;strong&gt;Code&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#663300;"&gt;/* SimpleHandler interface. */&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#663300;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#663300;"&gt; &lt;/span&gt;&lt;span style="color:#009900;"&gt;var &lt;/span&gt;&lt;span style="color:#660000;"&gt;&lt;span style="color:#666666;"&gt;SimpleHandler&lt;/span&gt; ={&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;request:function&lt;/span&gt;&lt;span style="color:#990000;"&gt;( method , url , calback , postVars)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;   &lt;/span&gt;&lt;span style="color:#009900;"&gt;var &lt;/span&gt;&lt;span style="color:#666666;"&gt;self=SimpleHandler;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;    &lt;/span&gt;&lt;span style="color:#990000;"&gt;/* &lt;em&gt;This  calls the factory method createXhrObject&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;      * to return an instant of the request handler&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;      * depending on the kind of browser the &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;      * client is using&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;      */&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;   &lt;/span&gt;&lt;span style="color:#009900;"&gt;var &lt;/span&gt;&lt;span style="color:#666666;"&gt;xhr=self.createXhrObject();&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;         xhr.onreadystatechange=function()&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;         {&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;              if(xhr.readyState!==4) return;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;              (xhr.status==200)? &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;              callback.success(xhr.responseText):&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;              callback.failure(xhr.status);&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;         };&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;         xhr.open( method , url , postVars);&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;         if(method !=='POST') postVars=null;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;         xhr.send(postVars);&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;},&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt; /* The factory method that create an&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;   * instant of the request object&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;   * depending on the browser type&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;   */&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;createXhrObject:function()&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;     &lt;/span&gt;&lt;span style="color:#009900;"&gt;var &lt;/span&gt;&lt;span style="color:#666666;"&gt;methods=[&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                               function(){return new XMLHttpRequest();},&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                               function(){ return new ActiveXObject('Msxml2.XMLHTTP');},&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                               function(){ return new ActiveXObject('Microsoft.XMLHTTP');}  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                             ];&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;       for(var i=0 ; var len=method.length ; i&lt;&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;           {&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                 try&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                  { &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                      methods[i]();&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                   }&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                   catch(e)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                   {&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                     continue;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                    &lt;/span&gt;&lt;span style="color:#990000;"&gt;/* if we get to this point, methods[i] worked */&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                     &lt;/span&gt;&lt;span style="color:#009900;"&gt;var &lt;/span&gt;&lt;span style="color:#666666;"&gt;self= SimpleHandler&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                      self.createXhrObject= methods[i];&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;                       return methods[i];&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;           }&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;         &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;           &lt;/span&gt;&lt;span style="color:#990000;"&gt; /* if we get to this point anyway, none of the methods worked */&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;            &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;            throw new Error('Simplehandler: Could not create an Ajax request handler');&lt;/span&gt;&lt;span style="color:#666666;"&gt;     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#666666;"&gt;},&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#990000;"&gt;     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#660000;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;To use this factory example you need to  know the &lt;strong&gt;method&lt;/strong&gt; of request, whether POST or GET,&lt;/span&gt;&lt;br /&gt;the &lt;strong&gt;url&lt;/strong&gt; you will be sending you request to, the &lt;strong&gt;data&lt;/strong&gt; you want to send to the server,&lt;br /&gt;the &lt;strong&gt;callback&lt;/strong&gt; function that handles response from&lt;br /&gt;the server. Now the callback function is actually  an object with two functions namely, &lt;strong&gt;success&lt;/strong&gt; and &lt;strong&gt;fialure&lt;/strong&gt;&lt;br /&gt;It is usually defined as follows&lt;br /&gt;var &lt;strong&gt;callback&lt;/strong&gt;={success:function(responseText){alert('Success: ' + responseText);},&lt;br /&gt;                          failure:function(statusCode){alert('Failure ' + statusCode);&lt;br /&gt;                         };&lt;br /&gt; So to do the actual request you do this&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;SimpleHandler&lt;/span&gt;.&lt;span style="color:#ff0000;"&gt;request&lt;/span&gt;(&lt;strong&gt;method&lt;/strong&gt; , &lt;strong&gt;url &lt;/strong&gt;, &lt;strong&gt;data&lt;/strong&gt;);&lt;br /&gt;This simple call first, gets the parameters you want to send to the server, the url to send it to,&lt;br /&gt;the method of sending POST or GET, it then internally determines the type of browser you are using in order to instantiate the correct request handler for the transaction.&lt;br /&gt;an instance of &lt;strong&gt;XMLHttpRequest&lt;/strong&gt; object indicate that you are using a browser that support the geko engine (Firefox,Safari,Apple etc). An instance of &lt;strong&gt;ActivexObject&lt;/strong&gt; with the &lt;strong&gt;Msxml2.XMLHTTP&lt;/strong&gt; parameter indicates that you are using the latest microsoft browser app- IE 7.0 and an instance of &lt;strong&gt;ActiveXObject&lt;/strong&gt; with parameter &lt;strong&gt;Microsoft.XMLHTTP&lt;/strong&gt; indicates that you are using version of IE less than 7.0&lt;br /&gt;The convinience method &lt;strong&gt;request&lt;/strong&gt; performs the steps needed to send off a request and process the reponse. it creates an XHR object, configures it ans sends the request. The interesting part is the creation of the XHR object. The factory method &lt;strong&gt;createXhrObject &lt;/strong&gt;returns an XHR object based on what is available in the current environment. The first time it is run, it will test three different ways of creating an XHR object, and when it finds one that works, it will return the object created and overwrite itself with the function used to create the object. This new function becomes the createXhrObject method. This techniques , can be used to create functions and methods that store complex calculations so that they do not have to be repeated. All of the complex setup code is called once, the first time the method is executed, and after that only the browser-specific code is executed. This is a form of caching technique on the client side that utilizies the browser specific codes only for optimised execution.&lt;br /&gt;Watchout for a review of the &lt;strong&gt;Bridge pattern &lt;/strong&gt;in javascript in my next post&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8297537222156961313-7980504746246102201?l=javascriptrev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javascriptrev.blogspot.com/feeds/7980504746246102201/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8297537222156961313&amp;postID=7980504746246102201' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default/7980504746246102201'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default/7980504746246102201'/><link rel='alternate' type='text/html' href='http://javascriptrev.blogspot.com/2008/06/factory-pattern-101.html' title='The Factory pattern (101)'/><author><name>Christian Amaonwu</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='20' height='32' src='http://3.bp.blogspot.com/_58l6ncjdQ6s/SYrBGt7YRBI/AAAAAAAAAA8/b6YZne8PnfE/S220/zala1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8297537222156961313.post-7867299168320833852</id><published>2008-05-28T03:00:00.000-07:00</published><updated>2008-05-28T03:07:08.176-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Advertising'/><category scheme='http://www.blogger.com/atom/ns#' term='Google AdWords'/><title type='text'>A Look at The Genesis of  Google AdWords</title><content type='html'>Have you ever thought about how the giant search engine of today,Google inc ever come up with the idea of ads on there site that is not only enriching them but millions of others arround the world? Well in my research i have uncovered an article that showed the innovative idea behind the Google AdWord revenue generation.You could read more about here&lt;br /&gt; &lt;a href="http://publishing2.com/2008/05/27/google-adwords-a-brief-history-of-online-advertising-innovation/"&gt;History of Google AdWords&lt;/a&gt;&lt;br /&gt;I hope you will find this an interesting read&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8297537222156961313-7867299168320833852?l=javascriptrev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javascriptrev.blogspot.com/feeds/7867299168320833852/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8297537222156961313&amp;postID=7867299168320833852' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default/7867299168320833852'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default/7867299168320833852'/><link rel='alternate' type='text/html' href='http://javascriptrev.blogspot.com/2008/05/look-at-genesis-of-google-adwords.html' title='A Look at The Genesis of  Google AdWords'/><author><name>Christian Amaonwu</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='20' height='32' src='http://3.bp.blogspot.com/_58l6ncjdQ6s/SYrBGt7YRBI/AAAAAAAAAA8/b6YZne8PnfE/S220/zala1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8297537222156961313.post-6685488218667967354</id><published>2008-05-28T02:03:00.000-07:00</published><updated>2008-05-28T02:40:36.293-07:00</updated><title type='text'>Browser Detection and Cross Browser Support</title><content type='html'>Have you ever designed a site that looked great in Explorer only for it to look messed up in Firefox or Opera? Well i have and i have looked for ways of dealing with this issue.While conducting a search on the net i came a cross this article that explored the problem.&lt;br /&gt;The article talked a lot about the various browsers and the methods for detecting the each&lt;br /&gt;the link to this article is &lt;a href="http://developer.mozilla.org/en/docs/Browser_Detection_and_Cross_Browser_Support"&gt;Browser Detecion and Cross Browser Support&lt;/a&gt;&lt;br /&gt;I hope those of you who have the same problem as i do will find this article a great read.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8297537222156961313-6685488218667967354?l=javascriptrev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javascriptrev.blogspot.com/feeds/6685488218667967354/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8297537222156961313&amp;postID=6685488218667967354' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default/6685488218667967354'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default/6685488218667967354'/><link rel='alternate' type='text/html' href='http://javascriptrev.blogspot.com/2008/05/browser-detection-and-cross-browser.html' title='Browser Detection and Cross Browser Support'/><author><name>Christian Amaonwu</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='20' height='32' src='http://3.bp.blogspot.com/_58l6ncjdQ6s/SYrBGt7YRBI/AAAAAAAAAA8/b6YZne8PnfE/S220/zala1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8297537222156961313.post-2748572634943348122</id><published>2008-05-24T05:02:00.000-07:00</published><updated>2008-05-24T06:24:36.248-07:00</updated><title type='text'>How do i pick up all the fields of a form with javascript?</title><content type='html'>I have devised a simple way of picking up all the datas in my form for either &lt;br /&gt;client side validation or for packaging and sending it to the server via Ajax&lt;br /&gt;I will illustrate this with a basic form with two input box and two select box&lt;br /&gt;the form structure first&lt;br /&gt;&lt;br /&gt; &amp;ltform method='post' action=''&amp;gt&lt;br /&gt;   &amp;lttable width='400'align='center'&amp;gt&lt;br /&gt;     &amp;lttbody&amp;gt&lt;br /&gt;       &amp;lttr&amp;gt&lt;br /&gt;           &amp;lttd&amp;gtFirstname&amp;lt/td&amp;gt&lt;br /&gt;  &amp;lttd&amp;gt&amp;ltinput type='text' id='csFname' name='ssFname'&amp;gt/&amp;lt/td&amp;gt&lt;br /&gt;       &amp;lt/tr&amp;gt&lt;br /&gt;       &amp;lttr&amp;gt&lt;br /&gt;           &amp;lttd&amp;gtLastname&amp;lt/td&amp;gt&lt;br /&gt;  &amp;lttd&amp;gt&amp;ltinput type='text' id='csLname' name='ssLname'&amp;gt/&amp;lt/td&amp;gt&lt;br /&gt;       &amp;lt/tr&amp;gt&lt;br /&gt; &amp;lttr&amp;gt&lt;br /&gt;           &amp;lttd&amp;gtAge&amp;lt/td&amp;gt&lt;br /&gt;  &amp;lttd&amp;gt&amp;ltselect id='csAge' name='ssAge'&amp;gt&lt;br /&gt;    &amp;lt option value=''&amp;gtSelect one&amp;lt option &amp;gt&lt;br /&gt;    &amp;lt option value='20'&amp;gt20&amp;lt option &amp;gt&lt;br /&gt;    &amp;lt option value='30'&amp;gt30&amp;lt option &amp;gt&lt;br /&gt;    &amp;lt /select &amp;gt&lt;br /&gt;  &amp;lt/td&amp;gt&lt;br /&gt;       &amp;lt/tr&amp;gt&lt;br /&gt;&amp;lttr&amp;gt&lt;br /&gt;           &amp;lttd&amp;gtSex&amp;lt/td&amp;gt&lt;br /&gt;  &amp;lttd&amp;gt&amp;ltselect id='csSex' name='ssSex'&amp;gt&lt;br /&gt;    &amp;lt option value=''&amp;gtSelect one&amp;lt option &amp;gt&lt;br /&gt;    &amp;lt option value='Male'&amp;gtMale&amp;lt option &amp;gt&lt;br /&gt;    &amp;lt option value='Female'&amp;gtFemale&amp;lt option &amp;gt&lt;br /&gt;    &amp;lt /select &amp;gt&lt;br /&gt;  &amp;lt/td&amp;gt&lt;br /&gt;       &amp;lt/tr&amp;gt&lt;br /&gt;   &amp;lt tr &amp;gt &amp;lt td colspan='2'&amp;gt &amp;lt input type='button' value='Submit'/&amp;gt&lt;br /&gt;    &amp;lt/ td &amp;gt &amp;lt /tr &amp;gt&lt;br /&gt;     &amp;lt/tbody&amp;gt  &lt;br /&gt;   &amp;lt/table&amp;gt&lt;br /&gt; &amp;lt/form&amp;gt&lt;br /&gt;All that is needed now is to write the script that will pick up all the data&lt;br /&gt;to do this i always use javascript objects method of coding&lt;br /&gt;or what is called the singleton pattern&lt;br /&gt;&lt;br /&gt;var handleForm={&lt;br /&gt;errorCode:0,&lt;br /&gt;dataToServer:null,&lt;br /&gt;errorMessage:null,&lt;br /&gt;/**&lt;br /&gt; *A function to start up the function when the page loads&lt;br /&gt; */&lt;br /&gt;initDoc:function()&lt;br /&gt;{&lt;br /&gt;  if(!document.getElementById &amp;&amp; !document.createTextNode)&lt;br /&gt;  {return;} &lt;br /&gt;},&lt;br /&gt;/**&lt;br /&gt; * A validating function validates all the form entries&lt;br /&gt; * Node this is a generic validator that determines&lt;br /&gt; * the type of object to be validated and then calls&lt;br /&gt; * the appropriate method to do the validating&lt;br /&gt; */&lt;br /&gt;validate:function(vtype,data)&lt;br /&gt;{&lt;br /&gt;  if(!vtype)&lt;br /&gt;   {return}&lt;br /&gt;    var self=handleForm;&lt;br /&gt;   switch(vtype)&lt;br /&gt;    {&lt;br /&gt;     case'name':&lt;br /&gt;       self.validateName(errorPlace,data);&lt;br /&gt;       break;&lt;br /&gt;     case'age':&lt;br /&gt;      self.validateAge(errorPlace,data);&lt;br /&gt;      break;&lt;br /&gt;     case'sex':&lt;br /&gt;      self.validateSex(errorPlace,data);&lt;br /&gt;      break;&lt;br /&gt;    }&lt;br /&gt;    return;&lt;br /&gt;},&lt;br /&gt;/**&lt;br /&gt; * Define the specific validating scheme for &lt;br /&gt; * all the entries in the validate function&lt;br /&gt; * for instance the name entries validator&lt;br /&gt; * would look like this&lt;br /&gt; */&lt;br /&gt;validateName:function(errorDiv,dataValue)&lt;br /&gt;{&lt;br /&gt;  var self=handleForm;&lt;br /&gt;   &lt;br /&gt;  var exp=%^[a-zA-Z]{3,}$%;&lt;br /&gt;   if(!dataValue.match(exp))&lt;br /&gt;    {&lt;br /&gt;      return self.discardValue(errorDiv,'Invalid name') ;&lt;br /&gt;    }else&lt;br /&gt;    {return self.acceptValue(errorDiv);}&lt;br /&gt;},&lt;br /&gt;/**&lt;br /&gt; * The discardValue and acceptValue function are &lt;br /&gt; *Helper function that informs the user when something&lt;br /&gt; *goes wrong and when some thing goes write&lt;br /&gt; */&lt;br /&gt;discardValue:function(errorDiv,errorMsg)&lt;br /&gt;{&lt;br /&gt;   var self=handleForm;  //references the class itself&lt;br /&gt; //get the place you display error, ususally in a div&lt;br /&gt;   var epanel=document.getElementById(errorDiv);&lt;br /&gt;    epanel.innerHTML='';&lt;br /&gt; &lt;br /&gt;//set the errorCode to a number greater than 0, this tells your script &lt;br /&gt;//stop any process when there is an error somewhere&lt;br /&gt;  self.errorCode=434;&lt;br /&gt;  epanel.innerHTML=errorMsg;  &lt;br /&gt;    return;&lt;br /&gt;},&lt;br /&gt;/**&lt;br /&gt; * This is fired when the is a correct value or acceptable value&lt;br /&gt; * it set the errorCode back to 0 and clears the error display place&lt;br /&gt; */&lt;br /&gt;acceptValue:function(errorDiv)&lt;br /&gt;{&lt;br /&gt;  var self=handleForm; &lt;br /&gt;  var epanel=document.getElementById(errorDiv);&lt;br /&gt;  epanel.innerHTML='';&lt;br /&gt;  self.errorCode=0;&lt;br /&gt;  return;&lt;br /&gt;},&lt;br /&gt;/**&lt;br /&gt; * We define the function that is called&lt;br /&gt; * when the submit button is clicked&lt;br /&gt; *note that this does the picking,validating and packaging&lt;br /&gt; * of the data for serverside process&lt;br /&gt; */&lt;br /&gt;getData:function()&lt;br /&gt;{&lt;br /&gt;  //define and object array&lt;br /&gt;   var ddata=['csFirstname':null,&lt;br /&gt;              'csLastname':null,&lt;br /&gt;              'csAge':null,&lt;br /&gt;              'csSex':null&lt;br /&gt;             ];&lt;br /&gt;&lt;br /&gt;   //get all the input object in the form&lt;br /&gt;     var inputs=document.getElementsByTagName('input');&lt;br /&gt;     &lt;br /&gt;   //get all the select object in the form&lt;br /&gt;    var selects=document.getElementsByTagName('select');&lt;br /&gt;    &lt;br /&gt;    //loop through all the input object validating and putting then into&lt;br /&gt;    // the object array ddata&lt;br /&gt;&lt;br /&gt;    var self=handleForm;&lt;br /&gt;&lt;br /&gt;    for(var i=0;i&amp;ltinputs.length;i++)&lt;br /&gt;       {&lt;br /&gt;          var e=inputs[i];&lt;br /&gt;            if(e.type=='text' &amp;&amp; e.value.length&amp;gt0)&lt;br /&gt;              {&lt;br /&gt;                //here we determine the type of object it is so&lt;br /&gt;                // that we can validate it&lt;br /&gt;                //remove the prefix cs from the id and pass it to the validating&lt;br /&gt;                // function&lt;br /&gt;                var thetarget=e.id.substring(2,e.id.length);&lt;br /&gt;                self.validate(thetarget,e.value);&lt;br /&gt;                &lt;br /&gt;                //break out of the loop if the is a problem&lt;br /&gt;                 if(self.errorCode&amp;gt0)                   &lt;br /&gt;                   {&lt;br /&gt;                    break;&lt;br /&gt;                   }else&lt;br /&gt;                   {&lt;br /&gt;                     // add the value to the array object&lt;br /&gt;                     ddata[e.id]=e.value;&lt;br /&gt;                   } &lt;br /&gt;              }else&lt;br /&gt;               {//fields are empty&lt;br /&gt;                  alert('Please fill out the form');&lt;br /&gt;               }&lt;br /&gt;       }&lt;br /&gt;  //that does it for all the input fields&lt;br /&gt;  // now for the select fields it is still the same loop but with slight difference&lt;br /&gt;  &lt;br /&gt;   for(var k=0;k&amp;ltselects.length;k++)&lt;br /&gt;   {&lt;br /&gt;       var d=selects[k];&lt;br /&gt;       if(d.selectedIndex&amp;gt0)&lt;br /&gt;         {&lt;br /&gt;           //pick out each for validation&lt;br /&gt;           var thetarget=d.id.substring(2,d.id.length);&lt;br /&gt;           self.validate(thetarget,d.options[d.selectedIndex].value);&lt;br /&gt;           if(self.errorCode&amp;gt0)&lt;br /&gt;              {&lt;br /&gt;               //a problem break;&lt;br /&gt;              }else&lt;br /&gt;              {&lt;br /&gt;                //add to the object array&lt;br /&gt;                ddata[d.id]=d.options[d.selectedIndex].value;&lt;br /&gt;              }&lt;br /&gt;         }else&lt;br /&gt;         {// an empty select box&lt;br /&gt;           alert('Please select something');&lt;br /&gt;            break;&lt;br /&gt;          }&lt;br /&gt;   }&lt;br /&gt;    if(self.errorCode&amp;gt0)&lt;br /&gt;    {&lt;br /&gt;      // the was a problem stop the processing&lt;br /&gt;      return;&lt;br /&gt;    }&lt;br /&gt;     self.dataToServer=ddata;&lt;br /&gt;     var formattedData=self.encodeData();&lt;br /&gt;   //here goes the Ajax call to the server;&lt;br /&gt;},&lt;br /&gt;/**&lt;br /&gt; * If all the validating went fine without errorCode going beyond 0&lt;br /&gt; * We then encode all the data in the object array for Ajax transmission&lt;br /&gt; * The function bellow does just that&lt;br /&gt; */&lt;br /&gt;encodeData:function()&lt;br /&gt;{&lt;br /&gt;  var self=handleForm;&lt;br /&gt;   var str='ajax=1'; &lt;br /&gt;  var items=self.dataToServer;&lt;br /&gt;  for(var item in items)&lt;br /&gt;     {&lt;br /&gt;         str+='&amp;'+ encodeURIComponent(item)+'='+ encodeURIComponent(items[item]);&lt;br /&gt;     }&lt;br /&gt;   return str;&lt;br /&gt;}&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8297537222156961313-2748572634943348122?l=javascriptrev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javascriptrev.blogspot.com/feeds/2748572634943348122/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8297537222156961313&amp;postID=2748572634943348122' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default/2748572634943348122'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default/2748572634943348122'/><link rel='alternate' type='text/html' href='http://javascriptrev.blogspot.com/2008/05/how-do-i-pick-up-all-fields-of-form.html' title='How do i pick up all the fields of a form with javascript?'/><author><name>Christian Amaonwu</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='20' height='32' src='http://3.bp.blogspot.com/_58l6ncjdQ6s/SYrBGt7YRBI/AAAAAAAAAA8/b6YZne8PnfE/S220/zala1.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8297537222156961313.post-4092804940354790047</id><published>2008-05-24T04:29:00.000-07:00</published><updated>2008-05-24T06:39:42.334-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='HTML'/><title type='text'>How do i load select object with javascript</title><content type='html'>To load a select object with javascript we will write two simple functions called&lt;br /&gt;doLoad,loadSelect passing in the select object reference and the data to be loaded&lt;br /&gt;Here we assume the data is comming from an XML file from the server. let's first take&lt;br /&gt;a look at the XML file before we go ahead to write the function&lt;br /&gt;data.xml&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt?xml version='1.0' encoding='utf-8'?&amp;gt&lt;br /&gt;&amp;ltStates&amp;gt&lt;br /&gt; &amp;ltstate stateName='Anambra' stateCode='100'/&amp;gt&lt;br /&gt; &amp;ltstate stateName='Adamawa' stateCode='101'/&amp;gt&lt;br /&gt; &amp;ltstate stateName='Bauchi' stateCode='102'/&amp;gt&lt;br /&gt; &amp;ltstate stateName='Edo' stateCode='103'/&amp;gt&lt;br /&gt;  .&lt;br /&gt;  .&lt;br /&gt;  .&lt;br /&gt;&amp;lt/States&amp;gt&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;if we wanted to load this data in to a select object we first define our doLoad function&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;function doLoad(xmlDoc)&lt;br /&gt;{&lt;br /&gt; &lt;br /&gt;  /**Here we pick up the select object we want&lt;br /&gt;   * to load based on the id we assigned to it&lt;br /&gt;   */&lt;br /&gt;  var selObject=document.getElementById('SelectId');&lt;br /&gt;  if(!selObject)&lt;br /&gt;    {return;}&lt;br /&gt;   /**&lt;br /&gt;    * Next we get the state element of the XML file&lt;br /&gt;    * This will make docRoot an array of object we could&lt;br /&gt;    *loop through&lt;br /&gt;    */&lt;br /&gt;    var docElem=xmlDoc.getElementsByTagName('state');&lt;br /&gt; &lt;br /&gt;    /**&lt;br /&gt;     * We call the loadSelect function to do the actual work&lt;br /&gt;     * Passing it the selectObject and the docElem&lt;br /&gt;     */&lt;br /&gt;       &lt;br /&gt;       loadSelect(selObject,docElem);&lt;br /&gt;       return;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt; And that ends the doLoad function, next we look at the loadSelect function&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;function loadSelect(targetObj,data)&lt;br /&gt;{&lt;br /&gt;   if(!targetObj || !data) &lt;br /&gt;     {return;}&lt;br /&gt;    &lt;br /&gt;    for(var k=0;k&amp;ltdata.length;k++)&lt;br /&gt;    {&lt;br /&gt;      var options=data[k];&lt;br /&gt;      var option=document.createElement('option');&lt;br /&gt;       option.value=options.getAttribute('stateCode');&lt;br /&gt; option.appendChild(document.createTextNode(options.getAttribute('stateName')));&lt;br /&gt;     targetObj.appendChild(option);&lt;br /&gt;     option=null;&lt;br /&gt;     options=null;&lt;br /&gt;      &lt;br /&gt;    }&lt;br /&gt;   return;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And that does the loading of the XML data into the select object&lt;br /&gt;Note that the structure of the XMl data matters a lot when it comes to loading &lt;br /&gt;the Select Object because Javascript has a number of ways of dealing with &lt;br /&gt;XMl data with its DOM capability, i have used the most basic way of dealing &lt;br /&gt;with XML using javascript DOM&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8297537222156961313-4092804940354790047?l=javascriptrev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javascriptrev.blogspot.com/feeds/4092804940354790047/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8297537222156961313&amp;postID=4092804940354790047' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default/4092804940354790047'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8297537222156961313/posts/default/4092804940354790047'/><link rel='alternate' type='text/html' href='http://javascriptrev.blogspot.com/2008/05/how-do-i-load-select-object-with.html' title='How do i load select object with javascript'/><author><name>Christian Amaonwu</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='20' height='32' src='http://3.bp.blogspot.com/_58l6ncjdQ6s/SYrBGt7YRBI/AAAAAAAAAA8/b6YZne8PnfE/S220/zala1.JPG'/></author><thr:total>0</thr:total></entry></feed>
