Solved

Javascript dropdown menu link

Posted on 2001-06-05
8
237 Views
Last Modified: 2011-10-03
I am using the following javascript but I need to be able to have multiple dropdown lists on the same page.

<script language="JavaScript">
function pulldown_menu()
{
// Create a variable url to contain the value of the
// selected option from the the form named pulldown and variable selectname
var url = document.pulldown.selectname.options[document.pulldown.selectname.selectedIndex].value

// Re-direct the browser to the url value
window.location.href = url
}
</script>
0
Comment
Question by:dovcamp
  • 5
  • 3
8 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 150 total points
Comment Utility
Okay you have a form named pulldown and the select is named selectname


And I assume that you are triggering the function with the onchange event of the select.

with: onChange="pulldown_menu()"

All you have to do is elimnate the hard coded names with

onChange="pulldown_menu(this)"

And change the function to:


function pulldown_menu(EL)
{
var url = EL.options[EL.selectedIndex].value

// Re-direct the browser to the url value
window.location.href = url
}

Then you can add additional selects in the same format the the present form, or add a new form with additional selects.

Cd&
0
 
LVL 4

Author Comment

by:dovcamp
Comment Utility
Ok, here is my code, what am I doing wrong?

Thanks.


<HTML>

<HEAD>
     <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
    <LINK rel="stylesheet" href="style.css" type="text/css">
     <TITLE>Top Menu</TITLE>

<script language="JavaScript">
function pulldown_menu(EL)
{
var url = EL.options[EL.selectedIndex].value

// Re-direct the browser to the url value
window.location.href = url
}
</script>

</HEAD>
<body>
<TABLE BORDER="0" width="502">
     <tr>
      <td align="center">
       <img src="images/console_01.jpg" width="87" height="80" border="0" alt="">
      </td>
      <td align="center">
       <img src="images/console_02.jpg" width="87" height="85" border="0" alt="">
      </td>
      <td align="center">
         <img src="images/console_03.jpg" width="87" height="80" border="0" alt="">
      </td>    
      <td class="boldtext" align="center">
      Manage Resources
      </td>
      <td class="boldtext" align="center">
      Manage Site
      </td>
     </tr>
     <TR>
       <td>
        <form name="pulldown">
           <select name="selectname" SIZE="1" onChange="pulldown_menu(1)">
            <option value="">Select Option</option>
            <option value="add_report.html">Add Report</option>
            <option value="">Change Report</option>
            <option value="">Delete Report</option>
           </select>
       </td>
       <td>
           <select name="selectname" SIZE="1" onChange="pulldown_menu(2)">
            <option value="add_factsheet.html">Select Option</option>
            <option value="">Add Factsheet</option>
            <option value="">Change Factsheet</option>
            <option value="">Delete Factsheet</option>
           </select>
       </td>
       <td>
           <select name="selectname" SIZE="1" onChange="pulldown_menu(3)">
            <option value="">Select Option</option>
            <option value="add_newsitem.html">Add News Item</option>
            <option value="">Change News Item</option>
            <option value="">Delete News Item</option>
           </select>      
       </td>
       <td>
           <select name="selectname" SIZE="1" onChange="pulldown_menu(4)">
            <option value="">Select Option</option>-
            <option value="">Images</option>
            <option value="">Links</option>
              <option value="">Glossary</option>
               <option value="">Ratings</option>
            <option value="">Disclaimer</option>
           </select>
       </td>
       <td>
           <select name="selectname" SIZE="1" onChange="pulldown_menu(5)">
            <option value="">Select Option</option>
              <option value="">Manage Emails and Lists</option>
            <option value="">Manage Clients</option>
            <option value="">View Client Statistics</option>
           </select>
          </form>
       </td>
     </TR>
</TABLE>
</body>
</HTML>
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
<select name="selectname" SIZE="1" onChange="pulldown_menu(4)">
           
Two problems one minor and one major  

name="selectname"  -- you want to make that name unique to each select to avoid problems maintaining it.

onChange="pulldown_menu(4)">
Shoud be onChange="pulldown_menu(this)"

This is a JavaScript operator that returns the current object so in this context it is the same as:

document.pulldown.selectname

which is why you want a unique name for each select.  It then allows the function to be applied to any select where you call it.

Cd&

         

0
 
LVL 4

Author Comment

by:dovcamp
Comment Utility
That worked great.  Thanks.

One more question.  How can I direct the page that each dropdown goes to a specific frame target called "main"

Thanks.


0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 4

Author Comment

by:dovcamp
Comment Utility
Never mind.  I figured this last part out.

I put in:

// Re-direct the browser to the url value
parenet.main.href = url
}
0
 
LVL 4

Author Comment

by:dovcamp
Comment Utility
Thanks for all your help.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
Glad I could help.  You help a lot in the process, because you respond back with a good description of how you are.  Sometimes we have to ques and it make it tougher.  

Thanks for the A.  :^)

Cd&
0
 
LVL 4

Author Comment

by:dovcamp
Comment Utility
COBOLdinosaur,

One follow up question and I'll post it as a new question and give you points if you know the answer.

On the above Javascript is there a way to make it so that after a link is selected from one of the dropdown menus it refreshes the page so that all the dropdown menus go back to there original state, where the term "Select Option" is showing?

Thanks.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now