Home / Free JavaScripts / Combo Boxes / Here

Cut & Paste DHTML Select Menu

Credit: JavaScript Kit

Description: This script transforms ordinary SELECT elements on your page into custom DHTML drop down menus instead! The end result is a custom looking navigation menu based entirely on the SELECT menu's HTML. The original HTML is untouched as the script automatically goes about hiding the select menu while replacing that with its counterpart. It's time to give those combo boxes on your site an instant makeover!



Step 1: Add the following code to the <head> section of your page:

It references two external files and an image. Download them below (right click, and select "save as"):

Step 2: Add the below sample HTML to your page, which illustrates two DHTML select menus:

More Information

As mentioned, this script will transform your regular SELECT menus into a DHTML Menu instead. If you look at the code of Step 2, you'll see how it works exactly:

<!-- 1st example -->
<select id="webmaster" title="Developer Sites">
<option value="">JavaScript Kit</option>
<option value=""></option>
<option value="">Coding Forums</option>
<option value="">Dynamic Drive</option>
<option value="">CSS Drive</option>
<option value="">CSS Menus and codes</option>

<script type="text/javascript">
//dhtmlselect("id_of_select_menu", "optional_width_of_select_box_px", "optional_width_of_drop_down_menu_px")


The first portion is just your regular SELECT menu HTML with various options and urls defined (via the "value" attribute). To transform it into a DHTML menu, just call the JavaScript function:


immediately following the SELECT menu to replace it, where the ID of the menu is passed in as its parameter. You should call this function immediately following the HTML code, so the DHTML menu position on the page is identical to the original SELECT menu's.

Styling the DHTML Select Menu

To customize the look of the DHTML select menu, just modify the values inside dhtmlcombo.css. However, for each menu on your page, you can individually change the menu's width from the default. This is done by using two optional parameters when calling the dhtmlselect() function:

dhtmlselect("webmaster", "150px", "200px")

This causes the main box to be "150px", and the drop down menu that appears onMouseover to be "200px" for this particular DHTML select menu.

JavaScript Tools:
Site Info

CopyRight (c) 2018 JavaScript Kit. NO PART may be reproduced without author's permission. Contact Info