JavaScript
  Home arrow JavaScript arrow Page 3 - Finishing a List Generator with JavaScript
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Finishing a List Generator with JavaScript
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2006-12-12

    Table of Contents:
  • Finishing a List Generator with JavaScript
  • Listing the complete source code for the previous list generator
  • Displaying the source code for list-wrapped links
  • Listing the application's complete source code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Finishing a List Generator with JavaScript - Displaying the source code for list-wrapped links


    (Page 3 of 4 )

    As I expressed in the chapter that you just read, this list generating application is still incomplete, because it cannot display all the source code that corresponds to the already familiar list-wrapped links. Thus, in order to address this important issue, I'm going to define another key JavaScript function, in this case named "displayList()".

    As you'll see shortly, this function will be tasked with performing a few relevant tasks, like appending a <textarea> element to the web document tree, and populating it with the pertinent code of the dynamically-generated links. As a result, this will allow a quick copy/paste operation. Pretty simple, isn't it?

    Having explained the objective of this new function, below I listed its signature. It's as follows:    

    // display unordered list of links function displayList(){ // remove existing list boxes container var div=document.getElementById('listcontainer'); if(div){div.parentNode.removeChild(div)}; // create general containing DIV var div=document.createElement('div'); div.setAttribute('id','listcontainer'); div.className='elemcontainer'; // create <textarea> element var textarea=document.createElement('textarea'); textarea.setAttribute('rows','10'); textarea.setAttribute('cols','71'); // append <textarea> element to general DIV div.appendChild(textarea); // append general DIV to document tree document.getElementsByTagName('body')[0].appendChild(div); var items=document.getElementsByTagName('form')[1].elements; if(!items){return}; // get class value for list var listclass=document.getElementsByTagName('form')[0].
    elements[1].value; // get ID value for list var listid=document.getElementsByTagName('form')[0].
    elements[2].value; var listhtml='<ul'; if(listclass){listhtml+=' class="'+listclass+'"'}; if(listid){listhtml+='id="'+listid+'"'}; listhtml+='>n'; // generate XHTML list markup for(var i=0;i<items.length-1;i+=2){ if(items[i].getAttribute('type')!='button'){ listhtml+='<li><a href="'+items[i].value+'">
    '+items[i+1].value+'</a></li>n'; } } listhtml+='</ul>'; // include XHTML list markup into <textarea> element textarea.value=listhtml; // select XHTML list markup textarea.select();           }

    That's all you need to learn concerning the definition of the above function. As you can see, the function in question performs some useful tasks that were previously discussed, such as appending a regular <textarea> element to the web page, and filling this box with the markup that corresponds to the list-wrapped links.

    What's more, all the operations carried out by this function can be grasped much more easily if you take a look at the following image. It captures a particular instance of the application, where the respective <textarea> container has been populated with the (X)HTML of the list being generated dynamically:

    In this specific example, you can see that the application has neatly outputted all the markup that corresponds to a regular (X)HTML list, where each one of its items includes a link as well. Also, this code is displayed in the containing <textarea> element that I mentioned before, and certainly it's ready to be copied and pasted. Simple and efficient!

    Now that you have learned how the "displayList()" function fits into the whole picture, it's time to leap forward and face the last section of this article, where I'll be listing the complete source code for this JavaScript-based application, this time including the previously-defined function.

    To see how the entire list generator looks, jump straight into the following section and keep reading.

    More JavaScript Articles
    More By Alejandro Gervasio


       · Over this final part of this series, the list generator is finally completed, since...
     

    JAVASCRIPT ARTICLES

    - More on JavaScript Array Objects
    - Methods of the DOM Location Object
    - The DOM Location Object Properties
    - Handling Remote Files with JavaScript Click ...
    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...


     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT