Java Script Drop Down Menu With Css - - a full code for a dynamic drop down

free web hosting
Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

Java Script Drop Down Menu With Css - - a full code for a dynamic drop down

nickmealey
Introduction
This is a code that I use to dynamically create the drop down menus. First, you have to edit the following code and put it in your Javascript. Notice : /*** SET BUTTON'S FOLDER HERE ***/. Edit that to your folder. Also, the /*** SET BUTTONS' FILENAMES HERE ***/. This creates a mouseover when the drop down is activated. Put all your onmouseover images under: oversources = new array; and your onmouseout images under : upsources. Be sure to set your on and out images above each other.
CODE


/*** SET BUTTON'S FOLDER HERE ***/
var buttonFolder = "img/";

/*** SET BUTTONS' FILENAMES HERE ***/
upSources = new Array("image_out.gif","image_out.gif","image_out.gif","image_out.gif","image_out.gif");

overSources = new Array("image_on.gif","image_on.gif","image_on.gif","image_on.gif","image_on.gif");

// SUB MENUS DECLARATION, YOU DONT NEED TO EDIT THIS
subInfo = new Array();
subInfo[1] = new Array();
subInfo[2] = new Array();
subInfo[3] = new Array();
subInfo[4] = new Array();
subInfo[5] = new Array();

//*** SET SUB MENUS TEXT LINKS AND TARGETS HERE ***//
subInfo[1][1] = new Array("new","new.html","");
subInfo[1][2] = new Array("new","new.html","");
subInfo[1][3] = new Array("new","new.html","");
subInfo[1][4] = new Array("new","new.html","");
subInfo[1][5] = new Array("new","new.html","");
subInfo[1][6] = new Array("new","new.html","");
subInfo[1][7] = new Array("new","new.html","");

subInfo[2][1] = new Array("new","new.html");
subInfo[2][2] = new Array("new","new.html","");
subInfo[2][3] = new Array("new","new.html","");
subInfo[2][4] = new Array("Highschool","new.html","");



subInfo[3][1] = new Array("new","new.html","");
subInfo[3][2] = new Array("new","new.html","");
subInfo[3][3] = new Array("new","new.html","");
subInfo[3][4] = new Array("new","new.html","");
subInfo[3][5] = new Array("new","new.html","");

subInfo[4][1] = new Array("new","new.html","");
subInfo[4][2] = new Array("new","new.html","");
subInfo[4][3] = new Array("new","new.html","");
subInfo[4][4] = new Array("new","PO.html","");
subInfo[4][5] = new Array("new","new.html","");

subInfo[5][1] = new Array("new","new.html","");
subInfo[5][2] = new Array("new","new.html","");
subInfo[5][3] = new Array("new","new.html","");
subInfo[5][4] = new Array("new","new.html","");



//*** SET SUB MENU POSITION ( RELATIVE TO BUTTON ) ***//
var xSubOffset = 4;
var ySubOffset = 19;



//*** NO MORE SETTINGS BEYOND THIS POINT ***//
var overSub = false;
var delay = 1000;
totalButtons = upSources.length;

// GENERATE SUB MENUS
for ( x=0; x<totalButtons; x++) {
// SET EMPTY DIV FOR BUTTONS WITHOUT SUBMENU
if ( subInfo[x+1].length < 1 ) {
 document.write('<div id="submenu' + (x+1) + '">');
// SET DIV FOR BUTTONS WITH SUBMENU
} else {
 document.write('<div id="submenu' + (x+1) + '" class="dropmenu" ');
 document.write('onMouseOver="overSub=true;');
 document.write('setOverImg(\'' + (x+1) + '\',\'\');"');
 document.write('onMouseOut="overSub=false;');
 document.write('setTimeout(\'hideSubMenu(\\\'submenu' + (x+1) + '\\\')\',delay);');
 document.write('setOutImg(\'' + (x+1) + '\',\'\');">');


 document.write('<ul>');
 for ( k=0; k<subInfo[x+1].length-1; k++ ) {
  document.write('<li>');
  document.write('<a href="' + subInfo[x+1][k+1][1] + '" ');
  document.write('target="' + subInfo[x+1][k+1][2] + '">');
  document.write( subInfo[x+1][k+1][0] + '</a>');
  document.write('</li>');
 }
 document.write('</ul>');
}
document.write('</div>');
}





//*** MAIN BUTTONS FUNCTIONS ***//
// PRELOAD MAIN MENU BUTTON IMAGES
function preload() {
for ( x=0; x<totalButtons; x++ ) {
 buttonUp = new Image();
 buttonUp.src = buttonFolder + upSources[x];
 buttonOver = new Image();
 buttonOver.src = buttonFolder + overSources[x];
}
}

// SET MOUSEOVER BUTTON
function setOverImg(But, ID) {
document.getElementById('button' + But + ID).src = buttonFolder + overSources[But-1];
}

// SET MOUSEOUT BUTTON
function setOutImg(But, ID) {
document.getElementById('button' + But + ID).src = buttonFolder + upSources[But-1];
}



//*** SUB MENU FUNCTIONS ***//
// GET ELEMENT ID MULTI BROWSER
function getElement(id) {
return document.getElementById ? document.getElementById(id) : document.all ? document.all(id) : null;
}

// GET X COORDINATE
function getRealLeft(id) {
var el = getElement(id);
if (el) {
 xPos = el.offsetLeft;
 tempEl = el.offsetParent;
 while (tempEl != null) {
  xPos += tempEl.offsetLeft;
  tempEl = tempEl.offsetParent;
 }
 return xPos;
}
}

// GET Y COORDINATE
function getRealTop(id) {
var el = getElement(id);
if (el) {
 yPos = el.offsetTop;
 tempEl = el.offsetParent;
 while (tempEl != null) {
  yPos += tempEl.offsetTop;
  tempEl = tempEl.offsetParent;
 }
 return yPos;
}
}

// MOVE OBJECT TO COORDINATE
function moveObjectTo(objectID,x,y) {
var el = getElement(objectID);
el.style.left = x;
el.style.top = y;
}

// MOVE SUBMENU TO CORRESPONDING BUTTON
function showSubMenu(subID, buttonID) {
hideAllSubMenus();
butX = getRealLeft(buttonID);
butY = getRealTop(buttonID);
moveObjectTo(subID,butX+xSubOffset, butY+ySubOffset);
}

// HIDE ALL SUB MENUS
function hideAllSubMenus() {
for ( x=0; x<totalButtons; x++) {
 moveObjectTo("submenu" + (x+1) + "",-500, -500 );
}
}

// HIDE ONE SUB MENU
function hideSubMenu(subID) {
if ( overSub == false ) {
 moveObjectTo(subID,-500, -500);
}
}



//preload();





Creating your drop down options


Now, to create the your options simply edit the subinfo array. Notice that this is button 1 and has 4 menu options.
CODE

//*** SET SUB MENUS TEXT LINKS AND TARGETS HERE ***//
subInfo[1][1] = new Array("new","new.html","");
subInfo[1][2] = new Array("new","new.html","");
subInfo[1][3] = new Array("new","new.html","");
subInfo[1][4] = new Array("new","new.html","");



CSS

In CSS is where you create how the menu looks. You can edit the color of the background, border, ...ect. This menu will overlap anyother information underneathe the menu. I like to give it a little bit of transparency.
CODE


filter: alpha(opacity=75)


CODE


.dropmenu {
  position: absolute;
  left: -1500px;
  visibility: visible;
  z-index: 101;
  float: right;
  width: 150px;
  filter: alpha(opacity=85);

  border-width: 4px;
  border-style: outset;
  border-color: #888888;
  background-color: #333333;
}
.dropmenu ul {
  margin: 0;
  padding: 2;
  list-style-type: none;

}
.dropmenu li {
  display: inline;
}
.dropmenu a, .dropmenu a:visited, .dropmenu a:active {
  display: block;
  width: 150px;

  padding: 2px;
  margin: 1px;
  font-family: Verdana;
  font-size: 10px;
  font-weight: normal;
  text-align: left;
  text-decoration: none;

  color: #FFFFFF;
  background-color: #6282FA;
}
.dropmenu a:hover {
  padding: 2px;
  margin: 1px;
  font-family: Verdana;
  font-size: 10px;
  font-weight: normal;
  text-align: left;
  text-decoration: none;

  color: #0012ff;
  background-color: #EDA031;
}


If you have trouble witht the drop down being off set, set the margins wider.

 

 

 


Reply

nickmealey
also, put this in you html page:
CODE


<a href="new.html" onmouseover="setOverImg('1','');overSub=true;showSubMenu('submenu1','button1');" onmouseout="setOutImg('1','');overSub=false;setTimeout('hideSubMenu(\'submenu1\')',delay);" target="">
               <img src="img/CHE_classes_out.gif" border="0" id="button1" vspace="1" hspace="1" width="70" height="20"></a>

Reply

iGuest
How can I create fly drop down menu for text links ?
Java Script Drop Down Menu With Css

Hello sir,
How can I create fly drop down menu for text links ?
Please send me full code for this.

Thanks & Regards
NaiduGovindu

-question by Naidugovindu

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. jsf dropdown frame - 83.11 hr back. (1)
Similar Topics

Keywords : java script menu css code dynamic

  1. Java Mobile Applications - What you wanna have on your phone ? (7)
    I'm trying to do a Java mobile J2me application... But I don't know what to do... Any
    suggestions....? Maybe you guys can say what you would like to have on your mobile phone... ...
  2. Java And Xml: Links You Must Have - (1)
  3. Java Multithreading Issues - (2)
    So we have a web based application running on JBoss on several clustered servers. The front end of
    the application is using jms to communicate with the middleware MDB, which communicates with other
    backend application servers. The application runs well when only a few requests are submited.
    However, when requests boost to couple thousands, the app starts to crash. The log files shows a
    concurrency issue with the ThreadPoolExecutor. When we set the core size pool to one the issue was
    solved. Looks like we have concurrent issue of multiple threads accessing same resource s...
  4. How To Create Java Button Or Frame - to be customized (13)
    hi to all!!!! just like to ask if it would be possible if i could make a custom
    button or frame in java. i got tired of using the build infeatures in java. i would like to create
    my own dessign of button or frame.. can it be possible!!! /biggrin.gif' border='0'
    style='vertical-align:middle' alt='biggrin.gif' /> thank!!!! /laugh.gif'
    border='0' style='vertical-align:middle' alt='laugh.gif' /> New Help In! is NOT a descriptive
    topic title. Next time you decide not to follow the posting rules, you will be issued a w...
  5. Java Or C++ - (8)
    Many having tell me to make my MMORPG in java leads me to agree, But I'm not sure truly is it
    not yet easier, but yet the outcome of programming an MMORPG in java will make it fail or succeed
    more then one in C+= I've learned a lot of variables in javascript, and I don't think that
    java would be too bad either. My true question is, is those who use these languages, which seems
    to give better outcome, and which seems to be more in ease. Regards -PCessna...
  6. How To Implement Single Instance Application On Java - (0)
    See the next few lines containing Java Code: CODE 1. // imports    2. import
    sun.management.ConnectorAddressLink;      3. import sun.jvmstat.monitor.HostIdentifier;      4.
    import sun.jvmstat.monitor.Monitor;      5. import sun.jvmstat.monitor.MonitoredHost;      6. import
    sun.jvmstat.monitor.MonitoredVm;      7. import sun.jvmstat.monitor.MonitoredVmUtil;      8. import
    sun.jvmstat.monitor.MonitorException;      9. import sun.jvmstat.monitor.VmIdentifier;     10.  
      11. public static void main(String args[]) {     12.         /* The method Managem...
  7. Call Pdf995 From Java - (0)
    How can i call pdf995 engine from Java to generate Pdf from Doc. This approach from Visual Basic
    Application is provided in http://www.pdf995.com/faq_dev.html . How can i approach same from Java?
    Can anyone help? ...
  8. Auto Run Java Program - Run Java program on double click (11)
    Some of the installables in java comes in form of .jar file, one has to just double click or type
    "java -jar file.jar", and it starts executing. The reason for this is a line appended in the
    MANIFEST.MF file of that jar file. For writing a similar jar file of your own, just write your java
    file, then compile the same and create a jar file. Create a MANIFEST.MF file and the content should
    have the followings: CODE Manifest-Version: 1.0 Created-By: xyz Main-Class:
    xyz.MainClass Here xyz.MainClass is the main class. Now create a jar file with the man...
  9. Java Game - (2)
    Hi, I'm interested in game creation on websites. The game should be playable via web browser.
    I'm not new in programing, I know C++, C# and OpenGL api. But I'm new on Java. So I have
    some questions I want to ask You: Will I'l be able to create simple 2d game with java which
    would be playable via web browser? Simple 2d game means: timers, images, animated sprites, in game
    font. Will I'l be able to use OpenGL? Or I should use something different? Does Trap17 suports
    java graphics features I want? Thank You for Your time and answers....
  10. Java Object[][] Help - (2)
    I'm having some issues with working with objects . I get an index out of bounds ex.
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 heres how
    I'm using it ---------------------------- Object contestants = new Object {}; contestants
    = "test"; any ideas appreciated. Do I need to specify the initial size on creation or something?
    It seems I answered my own question I gave it an inital size then I was able to add things. But is
    there a way I can add to it on the fly without knowing its require maximum size?...
  11. Java Vs Javascript - (11)
    I thought they were completely different things. Surely javascript should be seperated from the rest...
  12. Learn Java Programming Language Online Step By Step - (0)
    I had found this site >> http://learnjava.awardspace.com This website is for people who want
    to learn Java Programming Language step by step. This website also includes JAVA lessons from the
    beginning to advanced level. So this site appropriates for the beginner of Java programmer language
    or non-basic Java Programming Language. The lessons are easy to follow and understand starting
    from how to get your PC JAVA ready, the fundamental programming concept and creating the real
    application. Moreover, the working examples are also included. Please enjoy the les...
  13. Javascript : No Right Click Script !@ - This script will allow you to protect your source coad ! (12)
    This script will help you to protect your source code Add this to Section of your site
    ! HTML <script language=JavaScript> var message="Function Disabled!";
    /////////////////////////////////// function clickIE4(){ if
    (event.button==2){ alert(message); return false; } } function
    clickNS4(e){ if
    (document.layers||document.getElementById&&!document.all){ if
    (e.which==2||e.which==3){ alert(message); return false; } } }
    if (docume...
  14. [help] Java Script: Window.open - Works with Firefox, not IE (8)
    CODE <HEAD> var popUpWin=0; function popUpWindow(URLStr) {
     if(popUpWin)  {    if(!popUpWin.closed) popUpWin.close();  }
     popUpWin = open(URLStr, 'GunBound Tactics: Screenshots',
    'width=820,height=550,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,top=90,left=90')
    ;; } </HEAD> <BODY> <a
    href="javascript:popUpWindow('/f11/clipped.php');"><b>Clips&
    #60;/b></a> This is a script for opening a new window. It works ...
  15. The Power Of Java - the best application that shows java features (14)
    Java technology has various usage from mobile applications to Enterprise applications. I think the
    power of Java technology in web applications and applets is showed in "meez.com" where u can create
    your own 3d avatars. /rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0"
    alt="rolleyes.gif" />...
  16. Jsp Or Java Chat Script Like Mig33 - (4)
    so most of you guys know mig33. its a wap application,probaly java.most kindly to be java. does
    anyone have java knowlege or knows where i can get a chat script like mig33? i also know this server
    supports jsp so im planing to use it for my application. i was hosted here last year but moved
    because i found a better host. now im back just to use the jsp on this server. Im planing to run
    chat applictions so if any one wants to help me in my project let me know....
  17. Java Helpdesk - All your queries regarding Java Programming goes here. (8)
    Hellow friends, I am creating this thread for all queries and suggestions related to java coding. If
    you face any problem, post it here, and others who have a solution can post the reply here. Hope it
    helps the users....
  18. Java Applet Query - (1)
    Hey there, I have made an applet that shows images moving about the screen. I have pause/resume
    buttons that work. But i've noticed that when the applet is interuppted by something i.e moving
    another window over it, it will automatically repaint. My question is how can I stop this? How can
    I make it so that the only time that paint is called is when I want it to be called? Thanks in
    advance!...
  19. Java Basic Program Guidance - (6)
    aving some problems taking in the Java at Uni, Was wondering if anyone could shine some light on it
    for me. My task is to write a program that will ask you to enter 2 words. the program will then
    print out both words on one line. However the words will be seperated by dots that will make the
    total length of the line 40. so if your first word was turtle and the second was abc, the output
    would be turtle...............................abc The program should check for certain conditions:
    1. a word can not be longer than 37 characters; 2. there must always be atlest 2 do...
  20. Ajax: Achieve Ajax Program In 5 Lines Of Code! - (1)
    Well Last night, after a week of irritation and errors I finally created an easy Javascript object
    that easily and quickly allows you to develop an AJAX program in just 5 easy steps! Here's
    the link to the object I've created: http://www.demolaynyc.astahost.com/ajaxConn/ajaxConn.js
    Download it and read the Readme file that's under the same directory:
    http://www.demolaynyc.astahost.com/ajaxConn/Readme.html Basically what this object does is to
    connect to a server-side script (".php, .asp, .jsp, etc"), and what ever this script displays is
    sent back ...
  21. Circular Movment/animation In Java? - (6)
    Hey there guys! How would i go about making an object move about a fixed point for a java
    applet? Thanks in advance guys! Regards, Rod...
  22. Beginning Java - where to start (10)
    does anyone know of any good websites with free java tutorials for people without a lot of prior
    coding experience? i've read some tutorials, but every one i read starts making references to C
    and C++... well i don't know either of those so it gets really really confusing really really
    fast. ive downloaded the sdk but that is it.... i know a pretty good amount of php and a tiny bit of
    perl but those are procedural languages so i dont know if they even helpe me at all with an OOP
    language like java....
  23. Java Iterator Help - I need help with a method using iterator (2)
    /** * Remove from the club's collection all members who * joined in the given month,
    and return them stored * in a sparate collection object. * @param month The month of the
    membership. * @param year The year of the membership. * @return The number of members.
    */ public ArrayList purge(int month, int year) { if(month >= 1 && month
    { Iterator it = members.iterator(); ArrayList purged;
    purged = new ArrayList(); int counter = 0; wh...
  24. Problem With Java Script Popup Form - Doesnt work in Safari (1)
    This code wont work in Safari, but works fine in Firefox 2. Can someone help. The error pops up
    however. It just doesn't do anything unless you dont pick one and then it says Pick a Windows
    tweak, but if you DO pick one it doesnt even try to load anything. Everything you see below is
    everything inside my PHP Include. If you would like to view my actual site it's
    http://boozkerstweaks.trap17.com There might be PHP errors and stuff right now, but i am working on
    those, but this i can not get. CODE <td  valign="top" class="right">
       ...
  25. Java editor - (72)
    In your opinion what's the best java editor/compiler? i use jcreator le and it works nicely......
  26. Helpful Registry Edit For Java Programmers - Command Prompt on right click menu (2)
    With this registry edit you can easily open the current folder in prompt without going through any
    Change Directory commands (cd). This is useful for people like me who are programming in JAVA, and
    every time to create class files and test them I have a diificult time just entering the commands in
    Prompt. But if you don't want to use this registry edit you can create the directory in
    C:\ drive like C:\files so you have to navigate very little in prompt. If you are
    experienced in regedit you can do it yourself shown below OR download the attachment and app...
  27. Java In A High School Software Design Course - Is it good? (5)
    Hi, I'm doing a course called Software Design and Development for HSC in a high school in
    Australia. HSC is basically the courses you do that you get assessed on for University entrance. I
    haven't really done programming before, although I've seen source code and can decipher it
    and make small changes. I am also quite good with the general use of computers. One of the major
    projects we will do in the course is the making of a game (although it's not just game-making
    that we do. We also have to develop a software solution package, although I'm not su...
  28. Java Part 1 - (2)
    The HTML <script> tag is used to insert a JavaScript into an HTML page. Examples Write text
    with Javascript - http://www.w3schools.com/js/tryit.asp?filename=tryjs_text The example
    demonstrates how to use JavaScript to write text on a web page. Write HTML with Javascript -
    http://www.w3schools.com/js/tryit.asp?file...ryjs_formattext The example demonstrates how to use
    JavaScript to write HTML tags on a web page. How to Put a JavaScript Into an HTML Page CODE
    <html> <body> [color=red]<script type="text/javascript"...
  29. Java Exercise Help - I need help to understand this question (2)
    Ok at my Uni they teach you OOP with java, They used to do with C++ i believe but swiched to java
    because its easier to teach people OOP with java apparently. Anyway I've been working on some
    exercises with java (book is 'objects first with java'). I've got this one exercise
    which I cant understand. QUOTE Exercise 4.29 Rewrite getLot so that it does not rely on a
    lot with a particular number being stored at index (number - 1) in the collection. For instance,
    if lot number 2 has been removed, then lot number 3 will have been moved from index 2 ...
  30. Simple Firefox Vs. Ie Script Bug; Need A Little Help - Simple script works in Firefox but not IE. (3)
    Hello I have a simple .js file that seems to work in Firefox but not IE. The error could totally be
    my syntax, just not sure why it's working in one browser and not the other. All I'm doing
    is waiting for an image to load completely before redirecting. I added an extra step that waits an
    additional 1.5 seconds just for 100% smooth transition (sometimes firefox reroutes before the image
    is actually fully loaded). This script works perfectly for Firefox, meaning if the image is already
    loaded/cached it reroutes immediately and if not, then waits with extra dela...



Looking for java, script, drop, menu, css, full, code, dynamic, drop

Searching Video's for java, script, drop, menu, css, full, code, dynamic, drop
advertisement



Java Script Drop Down Menu With Css - - a full code for a dynamic drop down



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE