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

x
?
Solved

Simple Script-loading drop down menu

Posted on 2000-03-01
6
Medium Priority
?
172 Views
Last Modified: 2013-12-25
I'd like to create a drop-down menu, but for each selection, I'd like to call a specific javascript.. Sort of like

<html>
<head>
<!-- javascripts here -->

</head>
<body>
<form name="form" >
  <select name="select">
    <option>Select one</option>
    <option>run js1</option>
    <option>run js2</option>
  </select>
</form>
...

Note: it should not require a submit button, since only one item can be selected.

Thanks!
-Sean
0
Comment
Question by:slydon
[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
  • 3
  • 2
6 Comments
 
LVL 18

Expert Comment

by:mgfranz
ID: 2574473
Sure, something like this;

<head>
<script language=javascript>

function JS1()

.... your code

end function

function JS2()

.... more of your code

end function

</head>
<body>

<form name="form" > 
  <select name="select">
    <option>Select one</option>
    <option value="javascript:JS1();">run js1</option>
    <option value="javascript:JS2();">run js2</option>
  </select>
</form>
</body>
</html>

Mark

0
 
LVL 19

Accepted Solution

by:
cheekycj earned 400 total points
ID: 2576892
or do this:

<head>
<script language=javascript>

function JS1() {
..
..
..
}

function JS2() {
..
..
..
}
function handle_select() {
if (document.myform.runselect.selectedIndex==0) {
  JS1();
} else if (document.myform.runselect.selectedIndex==1){

}
}
</script>
</head>
<body>

<form name="myform" > 
  <select name="rnselect" onChange="handle_select();">
    <option>Select one</option>
    <option>run js1</option>
    <option>run js2</option>
  </select>
</form>
</body>
</html>

0
 
LVL 1

Author Comment

by:slydon
ID: 2580787
Tried suggestion 1, as there would be more than 2 options, but something is still wrong.. perhaps its my formatting?
Using the Dreamweaver layer show/hide function as an example..


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF">
<p><a href="#" onMouseOver="MM_showHideLayers('Layer2','','hide','Layer1','','show')">open
  layer 1</a></p>
<p><a href="#" onMouseOver="MM_showHideLayers('Layer2','','show','Layer1','','hide')">layer
  2</a></p>
<div id="Layer2" style="position:absolute; width:200px; height:115px; z-index:2; left: 266px; top: 76px; visibility: hidden">gbdgfbgdgvdgf</div>
<div id="Layer1" style="position:absolute; width:200px; height:115px; z-index:1; visibility: hidden">gnfhhgbfbg</div>
<form name="form" >
  <select name="select">
    <option>Select one</option>
    <option value="javascript:MM_showHideLayers('Layer2','','hide','Layer1','','show');">run js1</option>
    <option value="javascript:MM_showHideLayers('Layer2','','show','Layer1','','hide');">run js2</option>
  </select>
</form>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:cheekycj
ID: 2581338
my comment was just an addition to the first one... you are not limited to just two... you just need to extend you if-then-else or use a switch statement.

CJ
0
 
LVL 1

Author Comment

by:slydon
ID: 2593208
Thanks CJ.. I'm going to try it out
-Sean
0
 
LVL 1

Author Comment

by:slydon
ID: 2760824
Took a bit of tweaking but I got it to work reasonably well. Thanks :)
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses

705 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