Solved

Simple Script-loading drop down menu

Posted on 2000-03-01
6
169 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 100 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

751 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