Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript dropdown menu link

Posted on 2001-06-05
8
Medium Priority
?
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 600 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

688 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