Style Sheets
  Home arrow Style Sheets arrow Page 4 - A More Complex Way of Building Replacement...
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? 
STYLE SHEETS

A More Complex Way of Building Replacement Combo Boxes
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-04-10

    Table of Contents:
  • A More Complex Way of Building Replacement Combo Boxes
  • Increasing our Options
  • Data Storage Format
  • Extracting the Data

  • 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


    A More Complex Way of Building Replacement Combo Boxes - Extracting the Data


    (Page 4 of 4 )

    Now that the XML file is available, we can extract the data inside it and do something with it. The next function is as follows:

    function writeOptions() {
      
    var options = file.getElementsByTagName("option");
      
    for (x = 0; x < options.length; x++) {
        
    var option = options[x].childNodes[0].nodeValue;
        
    var optionText = document.createTextNode(option);
        
    var newa = document.createElement("a");
        
    newa.className = "option";
        
    newa.href = "#";
         
    newa.onclick = function() {
          
    setOption(this);
        
    };
        
    var optionDiv = document.getElementById("combodiv");
        
    newa.appendChild(optionText);
        
    optiondiv.appendChild(newa);
      
    }
    }

    First, we set the contents of a new variable that holds an array of all of the elements in the XML file that match the specified string. Then a for loop executes once for each element in the options array. The first action is to get the text that is held in the element extracted from the XML file; this is done by addressing the nodeValue property of the first child node of the element, using the x variable to iterate through each element. We then create a variable that holds a newly created text node representing the text. Another variable is needed to hold an anchor element, of which we then set various properties. Next another variable is set that contains the text field in the HTML file. The text node we created is then appended to the anchor element, which is then appended to the text field in the DOM of the page.

    To make the page work as it did before, the file variable should be added to the JavaScript file, and then the init() method should be updated to call the getOptions() function. Also, don't forget to remove the contents of the combodiv in the HTML file.

    This method provides a more elegant way of adding options to the drop-down div, and while it would be possible to combine this with the previous way of using multiple divs to show additional options, it makes more sense code wise to use the overflow:auto rule in the CSS file to use a scroll bar where necessary, which should suffice in most situations. As you can see, it is easy to provide a much better looking drop-down box, that styles and functions consistently across the most popular browsers.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · In the first of these two articles, we looked at a quick and easy way of replacing...
     

    STYLE SHEETS ARTICLES

    - Improving the Visual Presentation of a CSS D...
    - Fixing Browser Incompatibilities in a CSS Dr...
    - Building Clean Drop-Down Menus with CSS
    - Creating Hybrid Web Page Layouts with Negati...
    - Creating Three-Column Web Page Layous with N...
    - Swapping Column Positions in Web Page Layout...
    - Creating Web Page Layouts with Negative Marg...
    - Creating Gradients for Individual Containers...
    - Creating Gradients for Web Page Headers with...
    - SEO Scrolling Frames Problem Solved
    - Building Cross-Browser Background Effects wi...
    - CSS: Pseudo
    - Using PNG Images to Build Background Effects
    - CSS: Continuing the Clarification of CSS Cla...
    - CSS: Top Secret Classification






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