Solved

Simple Script-loading drop down menu

Posted on 2000-03-01
6
163 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
  • 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now