JavaScript
  Home arrow JavaScript arrow Page 2 - 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 - Listing the complete source code for the previous list generator


    (Page 2 of 4 )

    As I usually do in all my articles on web development, I'd like to refresh some topics discussed in preceding tutorials. In this specific case, I want to list the complete source code for this list generating application, as it was originally defined in the first part of the series.

    Having said that, here is the complete definition for the mentioned JavaScript-based application:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" /> <title>JavaScript-based List Generator</title> <script language="javascript"> // display unordered list input boxes function displayListGenerator(selObj){ // check if user has selected the 'none' option if(selObj.value=='none'){alert('Please specify the number of
    list items to be created');return}; // remove existing 'gencontainer' DIV var div=document.getElementById('gencontainer'); if(div){div.parentNode.removeChild(div)}; // remove existing 'listcontainer' DIV var div=document.getElementById('listcontainer'); if(div){div.parentNode.removeChild(div)}; // create general containing DIV var div=document.createElement('div'); div.setAttribute('id','gencontainer'); div.className='elemcontainer'; // create form for list items var form=document.createElement('form'); // generate input boxes for list items for(var i=1;i<=selObj.value;i++){ var p=document.createElement('p'); // append label to paragraph p.appendChild(document.createTextNode('Link value ')); // create input box for href attribute var hrefbox=document.createElement('input'); hrefbox.setAttribute('type','text'); hrefbox.setAttribute('title','Enter value for "href"
    attribute here'); hrefbox.className='hrefbox'; // append href box to paragraph p.appendChild(hrefbox); // append label to paragraph p.appendChild(document.createTextNode('Link label ')); // create input box for link label var labelbox=document.createElement('input'); labelbox.setAttribute('type','text'); labelbox.setAttribute('title','Enter label of link
    here'); labelbox.className='labelbox'; //append label box to paragraph p.appendChild(labelbox); // append paragraph to form form.appendChild(p); } var p=document.createElement('p'); // create 'Generate list now!' button var button=document.createElement('input'); button.setAttribute('type','button'); button.setAttribute('value','Generate XHTML list now!'); button.className='button'; // append button to paragraph p.appendChild(button); // append paragraph to form form.appendChild(p); // append form to general DIV div.appendChild(form); // append general DIV to document tree document.getElementsByTagName('body')[0].appendChild(div); // assign 'onclick' event handler to button button.onclick=displayList; } // execute script when web page is loaded window.onload=function(){ if(document.getElementById&&document.createElement&&document.
    createTextNode){ var sel=document.getElementsByTagName('form')[0].
    elements[0]; if(!sel){return}; sel.onchange=function(){displayListGenerator(this)}; } } </script> <style type="text/css"> body{             padding: 0;             margin: 0;             background:#fff; } h1{             font: bold 24px Arial, Helvetica, sans-serif;             color: #000;             text-align:center; } form{             display: inline; } textarea{             width: 595px; } .elemcontainer{             width: 600px;             padding: 10px;             background:#eee;             margin-left:auto;             margin-right:auto;             margin-bottom:5px;             font: bold 12px Arial, Helvetica, sans-serif;             color: #000;             border: 1px solid #999; } .button{             width: 200px;            padding: 0px; } .labelbox,.hrefbox{             width: 200px; } </style> </head> <body> <h1>JavaScript-based XHTML List Generator</h1> <div class="elemcontainer"> <form> Number of list items <select name="numitems"> <option value="none">None</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> Class <input type="text" name="listclass" /> ID <input type="text" name="listid" /> </form> </div> </body> </html>

    As you'll possibly remember, the file listed above is still incomplete, since its JavaScript section contains a call to the "displayList()" function. This function hasn't been defined yet. This condition is clearly illustrated by the following line of code:

    // assign 'onclick' event handler to button

    button.onclick=displayList;

    Essentially, what the previous JavaScript statement means is that the form button labeled "Generate XHTML list now!", included within the pertaining user interface, will call the respective "displayList()" function. In this way it will show on the web page the complete source code that corresponds to the list-wrapped links that were dynamically constructed.

    Additionally, you should remember that the aforementioned source code will be displayed on a regular <textarea> element, therefore it can be easily copied and pasted into any text editor. As you'll realize, this implies that it's necessary to find out how the "displayList()" function looks.

    Taking into account this requirement, in the following section I'll show you the signature for this completely new function. Click on the link below and keep reading to learn more on this topic.

    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 1 hosted by Hostway
    Stay green...Green IT