SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Nov 2000
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Drop Down Menu

    Hi I have got a few scripts that I am trying to get to work but I don't know much about it, I'm just trying to peice it all together.

    This first part is so that I can open a program from the drop down menu. It is a whole page, but thought it might be easier this way.

    <html>
    <head>
    <title>test1</title>
    <script language="javascript">
    function RunProgram(progName){
    var objWSH = new ActiveXObject("WScript.Shell");
    var retval = objWSH.Run(progName,1,false);
    }
    </script>
    <script>
    function jmp(where) {
    var st = where.menu.options[where.menu.selectedIndex].value;
    if (st.substr(-3,3) == "exe")
    RunProgram(st);
    else
    location = st;
    }
    </script>
    </head>
    <body bgcolor="#FFFFFF">
    <div id="Layer2" style="position:absolute; width:200px; height:68px; z-index:2; left: 64px; top: 23px">
    <table width="151" border="0" cellspacing="0" cellpadding="0" align="left">
    <tr align="center" valign="middle">
    <td width="145">
    <form name="jump">
    <select name="menu">
    <option selected>applications....</option>
    <option value="javascript:RunProgram('C:\\Progra~1\\Window~1\\wmplayer.exe')">Media
    Player</option>
    </select>
    <div id="Layer1" style="position:absolute; width:52px; height:34px; z-index:1; left: 144px; top: 2px">
    <input type="image" onClick="jmp(this.form)" value="GO" name="button" src="images/go.gif">
    </div>
    </form>
    </td>
    </tr>
    </table>
    </div>

    </body>
    </html>

    //--------- That works fine and this next page also works fine---------\\

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="javascript">
    function RunProgram(progName){
    var objWSH = new ActiveXObject("WScript.Shell");
    var retval = objWSH.Run(progName,1,false);
    }
    </script>
    <script>
    function jmp(where) {
    var st = where.menu.options[where.menu.selectedIndex].value;
    if (st.substr(-3,3) == "exe")
    RunProgram(st);
    else
    location = st;
    }
    </script>
    <script>
    <!--
    function land(ref, target)
    {
    lowtarget=target.toLowerCase();
    if (lowtarget=="_self") {window.location=loc;}
    else {if (lowtarget=="_top") {top.location=loc;}
    else {if (lowtarget=="_blank") {window.open(loc);}
    else {if (lowtarget=="_parent") {parent.location=loc;}
    else {parent.frames[target].location=loc;};
    }}}
    }
    function jump(menu)
    {
    ref=menu.choice.options[menu.choice.selectedIndex].value;
    splitc=ref.lastIndexOf("*");
    target="";
    if (splitc!=-1)
    {loc=ref.substring(0,splitc);
    target=ref.substring(splitc+1,1000);}
    else {loc=ref; target="_self";};
    if (ref != "") {land(loc,target);}
    }
    //-->
    </script>
    </head>
    <body bgcolor="#FFFFFF">
    <form action="dummy" method="post"><select name="choice" size="1">
    <option>CHOOSE A LINK</option>
    <option value="testfile:///e|/absolu~3/cahoot/mainpa~2.htm*_blank">test</option>
    </select><input TYPE="button" VALUE="GO!" onClick="jump(this.form)"></form>
    </body>
    </html>

    I am trying to have the 2 menus on the same page, the first page menu will be for opening programs from my desktop and next to that will be the menu from the second page just to open other pages on my computer in a new window.

    I think I can see that it is to do with having this var st = where.menu.options[where.menu.selectedIndex].value; in two different scripts but I can figure out what part of what script needs to go.

    Can anyone peice the two together in one page? Thanks to anyone that can help

  2. #2
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do it, but you will have to rename all instances of "menu" in the second script to something else (something like "menu1"). That should be where the conflict is occurring.
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  3. #3
    SitePoint Addict
    Join Date
    Nov 2000
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Drop Down Menu

    Hiya and thanks for your input.

    I have tried what you suggested but I am still having problems, is there any other way? maybe combining both scripts into one?

  4. #4
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this and see if it works:
    <html>
    <head>
    <title>test1</title>
    <script language="javascript">
    function RunProgram(progName){
    var objWSH = new ActiveXObject("WScript.Shell");
    var retval = objWSH.Run(progName,1,false);
    }
    </script>
    <script>
    function jmp(where) {
    num=where.selectedIndex
    var st = where[num].value;
    if (st.substr(-3,3) == "exe")
    {RunProgram(st)}
    else
    {self.location = st}
    }
    </script>
    </head>
    <body bgcolor="#FFFFFF">
    <form name="jump">
    <select name="menu" onChange="jmp(this)">
    <option selected>applications....</option>
    <option value="java script:RunProgram('C:\\Progra~1\\Window~1\\wmplayer.exe')">Media Player</option>
    </select>
    <select name="choice" size="1" onChange="jmp(this)">
    <option>CHOOSE A LINK</option>
    <option value="testfile:///e|/absolu~3/cahoot/mainpa~2.htm*_blank">test</option>
    </select>
    </form>
    </body>
    </html>

  5. #5
    SitePoint Addict
    Join Date
    Nov 2000
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Drop Down Menu

    Hiya and thank you for your help.

    Unfortunatley that doesn't work either.

    I might be able to do it with the use of frames as this would separate the scripts but it isn't a very good way around it as it will mean having more than 3 frames to a page.

    Would welcome any other suggestions )

  6. #6
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the problem with the example I gave? It worked for me.

  7. #7
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    1) make sure your path is correct. You need 3 "\" after "C:" and 2 "\" for each directory on the hard drive.

    2) if you place the call to RunProgram within the option's value, you do not need to text for 'exe' and call it a second time, you simply need to 'eval' it.

    3) while the link example I gave uses 'location.href', it just as easily could have used 'window.open', 'alert', 'top.framename....', or any other valid javascript DOM/method.

    Vinny

    <html>
    <head>
    <title>test1</title>
    <script language="javascript">

    function RunProgram(progName){
    var objWSH = new ActiveXObject("WScript.Shell");
    var retval = objWSH.Run(progName,1,false);
    }

    function jmp(selObj)
    {
    eval(selObj.options[selObj.selectedIndex].value);
    }

    </script>
    </head>
    <body bgcolor="#FFFFFF">
    <form name="jump">
    <select name="menu" onChange="jmp(this)">
    <option selected>applications and links</option>
    <option value="javascript:RunProgram('C:\\\Windows\\notepad.exe')">Notepad</option>
    <option value="location.href='http://members.aol.com/grassblad.html'">GrassBlade</option>
    </select>
    </form>
    </body>
    </html>
    Where the World Once Stood
    the blades of grass
    cut me still

  8. #8
    SitePoint Addict
    Join Date
    Nov 2000
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problems again


    I don't seem to be having much luck with this.

    I tried the full script that you posted requestcode but when I clicked on the mediplayer link it goes to a "The page cannot be displayed" page instead of opening the program and when I choose the test link to a web page it doesn't do anything.

    Vinny your script is also bringing up errors for me


    Line: 11
    Char:1
    Error: Expected ';'
    Code: 0
    URL: (local drive)

    I've got a bit confused with all this, but not half as confused as I would be without your help thanks

  9. #9
    SitePoint Addict
    Join Date
    Nov 2000
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I have it! :)

    I am a happy man!

    Here it is....!

    <html>
    <head>
    <title>test101</title>
    //----This Part For The Programs----\\
    <script language="javascript">
    function RunProgram(progName){
    var objWSH = new ActiveXObject("WScript.Shell");
    var retval = objWSH.Run(progName,1,false);
    }
    </script>
    <script>
    function jmp(where) {
    var st = where.menu.options[where.menu.selectedIndex].value;
    if (st.substr(-3,3) == "exe")
    RunProgram(st);
    else
    location = st;
    }
    </script>
    //----This Part For Web Pages----\\
    <script>
    <!--

    function openWindow(url){
    popupWin = window.open(url, "targetWin");
    }

    function buildArray() {
    var a = buildArray.arguments;
    for (i=0; i<a.length; i++) {
    this[i] = a[i];
    }
    this.length = a.length;
    }

    var urls1 = new buildArray("",
    "file:///c|/folder/file.htm",
    "http://www.yahoo.com",
    "http://www.dhtml.com",
    "http://www.hotmail.com");

    function go(which, num, win) {
    n = which.selectedIndex;
    if (n != 0) {
    var url = eval("urls" + num + "[n]")
    if (win) {
    openWindow(url);
    } else {
    location.href = url;
    }
    }
    }

    // -->
    </script>
    </head>
    <body bgcolor="#FFFFFF">
    <form name="jump">
    <select name="menu">
    <option selected>applications....</option>
    <option value="javascript:RunProgram('C:\\Progra~1\\Window~1\\wmplayer.exe')">Media
    Player</option>
    </select>
    <input type="button" onClick="jmp(this.form)" value="GO" name="button">
    </form>
    <br>
    <form name="form1">
    <select name="menu1">
    <option>test1
    <option>1
    <option>2
    <option>3
    <option>4
    </select>
    <input type="button" name="goButton" value="go" onClick="go(this.form.menu1, 1, true)"></form>
    </body>
    </html>

    Thank you all for your help Hope this is of use to you.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •