Nov 21, 2009

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

free web hosting
Open Discussion > MODERATED AREA > 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.

 

 

 


Comment/Reply (w/o sign-up)

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>

Comment/Reply (w/o sign-up)

FeedBacker
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

Comment/Reply (w/o sign-up)



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*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : java, script, drop, menu, css, full, code, dynamic, drop

  1. Java And Jsp On Trap 17
    Java and jsp on trap 17 (2)
  2. Need Help With Javascript Drag And Drop Script
    Having trouble with javascript drag and drop script. (3)
    hi, i have been trying to create a drag and drop menu for my new website, so that the navigation
    menu can be moved around the site. This is the code i have: CODE Test run - Right click
    menu function coordinates(event) { if (event.button==2)   { var x=event.x; var y=event.y; }
    document.getElementById("element").style.left=x; document.getElementById("element").style.top=y;
    document.getElementById("element").style.visibility="visible"; var oldx=x; var oldy=y;
    window.onmouseup=end(); window.onmousemove=coordinates(event); } function end() { } #el....
  3. Java Script To Hide The Url In Address Bar
    Does any one know about this ? (8)
    Hello friends , just now i came accross a particular type of script which is capable of masking the
    URL which is seen in the Address bar of the webpage , that is by implementing the particular Java
    Script when the user visits a page eg. www.mysite.com , then it is possible for the admin of
    www.mysite.com to mask this site and display some other website in the viewers address bar. I came
    to know that such a script can be written using Java Scripts , Can any one get me the Script ??....
  4. Which Is Good Java Or Dot Net
    which is good (13)
    Hi, I want to know which is going to be a success in future. I've asked this question to
    many but all are giving my vague answers. I'm asking this question because i'm going to join
    a company where i can choose either dot net or java. Which one should i choose. Wax....
  5. How To Implement Single Instance Application On Java
    (5)
    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 ManagementFactory.getRun....
  6. Learn Java Programming Language Online Step By Step
    (1)
    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....
  7. Java Or C++
    (19)
    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....
  8. Java Applet Query
    (2)
    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!....
  9. Java Iterator Help
    I need help with a method using iterator (3)
    /** * 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....
  10. Helpful Registry Edit For Java Programmers
    Command Prompt on right click menu (3)
    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 apply it. I t....
  11. Lottery Script Help
    (5)
    I have written a simple lottery script that I want to manually use with my InvisionPlus forum and
    main web site. Currently I have a page with the lottery script on my main page that can be accessed
    from a redirection forum on my forums. The script creates a button on the lottery page of my main
    site that creates a number entry prompt that acts as a password field. If the lotto number is
    correct, then my user is taken to my winners forum where they post they won. The purpose of the
    lotto is for members to win account upgrades. My script though is not working. Here is the ....
  12. Jsp Or Java Chat Script Like Mig33
    (5)
    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.....
  13. Best Java Framework For J2ee?
    Your Opinion About The Best Java Framework (11)
    What is the best framework to make enterprise application using Java (J2EE)? Currently I am
    learning Spring and it is quite good eventhough it is very complicated in my opinion. Maybe someone
    can share which framework that you use What are its advantages and disadvantages? I seek a J2EE
    framework that supports JMS and offer quick development process.....
  14. What's The Relationship Between Javascript And Java
    are they the same or different (7)
    I think most of you always confuse about java and javascript .So I make this topic to talk about it.
    Javascript and Java ,they have the same first four letter. Java and Javascript is the two language
    is very popular in the web world.Java is the general-purpose programming language that you can
    create an application or an applet.Javascript is a script language that looks sort of like java;with
    it you can do various nifty things in web pages.They are independent languages ,used for different
    purposes.If you are interesting in creating a website you should learn how to w....
  15. Help Writing An Html Code (onclick Open Something)
    (12)
    hi, I am new in web development i want to make a page in which there are few buttons and on click
    of each button there is some hidden text field which becomes visible and user can enter the text he
    wish to in it. how can i ?....
  16. Java Helpdesk
    All your queries regarding Java Programming goes here. (10)
    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.....
  17. Is It Possible To Make A Splash Screen In Java?
    (6)
    (A splash screen is an image that pops up before you run a program, sometimes it tells you what
    portion of the program is being loaded. One example that immediately comes to mind is Ad-Aware,
    which you should probably get if you don't have it.) Is there anything that could do this in
    Java? I thought about having just a JFrame with the top bar and edges hidden, but I found nothing in
    the API that suggests that that's possible.....
  18. Java Basic Program Guidance
    (7)
    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....
  19. Java Web Start Jnlp And Mysql
    (3)
    I think I have nearly managed to create a JNLP file and get my application running successfully.
    Unfortunately I am having a problem connecting to a MySQL database when using Java Webstart, the
    error that I get is shown below which incidently works fine when I run the app from eclipse. Has
    anyone successfully managed to connect to MySQL using Java Web Start, if so could you please explain
    why the regular doesn't work in more detail or perhaps post an example of simple connection java
    file so I can edit it so it works with what I have already developed. Thanks in ad....
  20. How To Create Java Button Or Frame
    to be customized (17)
    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 week long ban. ....
  21. File Upload Script In Java
    File Upload Script in JAVA (5)
    Hi, I am developing my personal website in JSP. I need a file upload script written in JAVA. I got a
    script that is Upload Bean from javazoom.com but the problem is its working fine on Windows
    Operating SYstem but not working on LINUX server. When i pass LINUX path (like
    /home/usr/public_html) to bean it gives me error Check UploadBean properties in your JSP. I
    think this bean aspecting a windows path. Can anyone provide me JSP Smart Upload script or any
    other file upload bean in JAVA. For your information Smart Upload website has been closed. My
    email id is ....
  22. Java Mobile Applications
    What you wanna have on your phone ? (9)
    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... ....
  23. [help] Java Script: Window.open
    Works with Firefox, not IE (10)
    CODE 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'); }
    Clips This is a script for opening a new window. It works with Firefox and not
    Internet Explorer. IE gives a script error and it references a part of the code that has nothing to
    do with the script. Someone please tell me if you can figure out why. Used at this add....
  24. How To Insert Code With Javascript
    How to insert into a div an amount of code (11)
    Hi, I have the next html page CODE function insertcode() { var code =" blablabal babala
    babababab here comes header fadfafa anchor blalbababa " var myText =
    document.createTextNode(code); document.getElementById("content").appendChild(myText); } -->
    Insert Code This code insert the data as text. The html tags are not treated like markup.
    I need to insert the code in a time. I mean i can not go tag per tag. (E.g.
    document.createElement("p")... ) Is there any method to insert a pice of html code into a div and
    keep it like code not like tex....
  25. Learning Java
    (11)
    Does anyone knows a good tutorial or book to learn Java?. I need to learn it quickly for a course in
    the Uni. I have background in other programming languages such as C/C++ so i hope that helps. Thanks
    in advance for your feedback....
  26. Learning Java
    By The Book (5)
    I travel alot so I get a chance to catch up on my reading. I bought a book today about javascripts.
    I hope this will help me in creating my site which is currently being worked on. I want my site to
    look professional and effective. I am hoping that this will help in creating this. Next I plan on
    learning PHP, but since php is harder I will learn this first. I am a fast reader and I hope that I
    can learn this fast since having a site down for a long time looks bad on the owner. One reason I
    want to learn Javascript is to protect my site. I want to add a username and pa....
  27. Java Is Not Javascript; Javascript Is Not Java
    (2)
    Java, developed under the Sun Microsystems brand, is a full-fledged object-oriented programming
    language. It can be used to create standalone applications and a special type of mini application,
    called an applet. Applets are downloaded as separate files to your browser alongside an HTML
    document, and provide an infinite variety of added functionality to the Web site you are visiting.
    The displayed results of applets can appear to be embedded in an HTML page (e.g., the scrolling
    banner message that is so common on Java-enhanced sites), but the Java code arrives as a separ....
  28. Free online java compiler =)
    no need to download the sun java SDK =) (6)
    Hey everyone, I found a site with a free online java compiler where you choose a source .java file
    from your computer and click on compile on the webpage and you get instant .class files!
    /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" />.... heres the
    link: www.innovation.ch - its somewhere on their website /smile.gif" style="vertical-align:middle"
    emoid=":)" border="0" alt="smile.gif" /> Hope this helps in some way /wink.gif"
    style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />.......
  29. Java Script Sites
    (6)
    this is the best websites for javascript and other javascript.internet.com javascriptkit.com
    webdeveloper.earthweb.com/webjs www.javascript.com www.dynamicdrive.com/
    www.webdeveloper.com/javascript www.javascriptworld.com/scripts www.java-scripts.net
    www.hotscripts.com www.totalscripts.com www.123webmaster.com www.needscripts.com www.reallybig.com
    www.a1javascripts.com javascript.programmershelp.co.uk
    developer.netscape.com/tech/javascript/resources.html
    www.mountaindragon.com/javascript/resources.htm i'll make like this in cgi and php if u love
    it???so....... ....
  30. Java editor
    (75)
    In your opinion what's the best java editor/compiler? i use jcreator le and it works nicely.......

    1. Looking for java, script, drop, menu, css, full, code, dynamic, drop
Similar
Java And Jsp On Trap 17 - Java and jsp on trap 17
Need Help With Javascript Drag And Drop Script - Having trouble with javascript drag and drop script.
Java Script To Hide The Url In Address Bar - Does any one know about this ?
Which Is Good Java Or Dot Net - which is good
How To Implement Single Instance Application On Java
Learn Java Programming Language Online Step By Step
Java Or C++
Java Applet Query
Java Iterator Help - I need help with a method using iterator
Helpful Registry Edit For Java Programmers - Command Prompt on right click menu
Lottery Script Help
Jsp Or Java Chat Script Like Mig33
Best Java Framework For J2ee? - Your Opinion About The Best Java Framework
What's The Relationship Between Javascript And Java - are they the same or different
Help Writing An Html Code (onclick Open Something)
Java Helpdesk - All your queries regarding Java Programming goes here.
Is It Possible To Make A Splash Screen In Java?
Java Basic Program Guidance
Java Web Start Jnlp And Mysql
How To Create Java Button Or Frame - to be customized
File Upload Script In Java - File Upload Script in JAVA
Java Mobile Applications - What you wanna have on your phone ?
[help] Java Script: Window.open - Works with Firefox, not IE
How To Insert Code With Javascript - How to insert into a div an amount of code
Learning Java
Learning Java - By The Book
Java Is Not Javascript; Javascript Is Not Java
Free online java compiler =) - no need to download the sun java SDK =)
Java Script Sites
Java editor

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


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

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com