Style Sheets
  Home arrow Style Sheets arrow 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 
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


    (Page 1 of 4 )

    In part one we looked at an easy way to recreate the functionality of combo boxes, while also creating the ability to style them effectively across browsers. In this part, we're going to work on getting rid of the hard coding of option values in the event handlers for the options, and look at dealing with combo boxes that have more options. You'll need the source files from part one to build on, and your trusty text editor at your side.

    First of all, we can look at getting rid of the hard-coded option values that are sent to the JavaScript file in the onclick event of each element. We will still be sending a parameter, but instead of using the text that forms the option in the drop-down div, we can use the this keyword instead. Change the onclick function calls in the replacementcombos.html file to look like this (no pun intended):

    <div id="combodiv">
     
    <a class="option" href="#" onclick="setOption(this)">Option 1</a>
     
    <a class="option" href="#" onclick="setOption(this)">Option 2</a>
     
    <a class="option" href="#" onclick="setOption(this)">Option 3</a>
     
    <a class="option" href="#" onclick="setOption(this)">Option 4</a>
     
    <a class="option" href="#" onclick="setOption(this)">Option 5</a>
     
    <a class="option" href="#" onclick="setOption(this)">Option 6</a>
     
    <a class="option" href="#" onclick="setOption(this)">Option 7</a>
     
    <a class="option" href="#" onclick="setOption(this)">Option 8</a>
     
    <a class="option" href="#" onclick="setOption(this)">Option 9</a>
     
    <a class="option" href="#" onclick="setOption(this)">Option 10</a>
    </div>

    Ok, so we now have no hard-coded values, just the this keyword. In this example, this refers to the element that the onclick is a property of. So when the user clicks on an option, the function is called and the parameter refers to whichever anchor element (option) was clicked instead of just being passed the text that we want to add to the text field.

    We now have to use a little DOM jiggery-pokery to get at the actual text content. In the combo.js file, change the setOption() function so that it appears as follows:

    function setOption(element) {
      
    var selection = element.childNodes[0].nodeValue;
      
    var combo = document.getElementById('combofield').value = selection;
      
    document.getElementById('combodiv').style.display = "none";
      
    comboopenflag = "off";
    }

    The text that the visitor sees as an option in the combo div is a textNode in the DOM, and appears as a child of the a element. So element.childNodes[0] refers to the first child of the a element and the actual text is contained in the nodeValue property. Other than this, the function is exactly the same as before. So we've gotten rid of the hard-coded option values and the page functions pretty much as it did before. Next we should adjust it to handle combo boxes with more options.

    More Style Sheets Articles
    More By Dan Wellman


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

    STYLE SHEETS ARTICLES

    - Using the Golden Ratio in Liquid Web Page De...
    - Fundamental Design Principles for Web Page L...
    - Pulling Web Page Elements with the Blueprint...
    - Pushing Web Page Columns with the Blueprint ...
    - Controlling Column Padding with the Blueprin...
    - Prepending Classes in the Blueprint CSS Fram...
    - Appending Grid Units with the Blueprint CSS ...
    - Changing Grid Units in the Blueprint CSS Fra...
    - The Blueprint CSS Framework
    - Building a Liquid Design with Evened Margins...
    - An Evened Margin Approach to Centering DIVs ...
    - Using Auto Margins with Multiple Columns to ...
    - Using Auto Margins with a Liquid Layout to C...
    - Using Auto Margins to Center DIVs with CSS
    - Using the Text-align CSS Property to Center ...







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