Solved

Simple Script-loading drop down menu

Posted on 2000-03-01
6
170 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
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).

636 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