Solved

Javascript dropdown menu link

Posted on 2001-06-05
8
240 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
ID: 6158041
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
ID: 6159454
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
ID: 6160356
<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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Author Comment

by:dovcamp
ID: 6160437
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
 
LVL 4

Author Comment

by:dovcamp
ID: 6160455
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
ID: 6160460
Thanks for all your help.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6160485
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
ID: 6183747
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

840 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