Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Simple Javascript Error | Please Help

I have found a tool that a former employee developed when he worked where I do. It is basically a webpage that helps people here perform various pings and reboot commands faster. It is very basic. Although the version he had was cluttered and messy. I decided to redesign it myself with the knowledge that I have learned from this site. However now that I have redesigned the page, something in the code is not working.

For example. If I click the "Continuous Ping" button, it will actually run all three buttons (Continuous Ping, Port 4000 Reboot, and Refresh Content/Reboot). Please let me know if you see something wrong.

<!DOCTYPE HTML>

<!--
    OSA Dev Tool Revision 2.0
    -------------------------
    Developed by: Ed
    Template by: Bob
    Revised Web Design by: Corey
-->

<html>

    <head>

        <!-- title -->
        <title>OSA Dev Tool 2.0</title>

        <!-- css -->
        <link rel="stylesheet" href="css/osadevtooldark.css" type="text/css" />

        <!-- script -->
        <script language="JavaScript" type="text/javascript">

        MyObject = new ActiveXObject( "WScript.Shell" );

        function fnTrapKD(btn, event){


         if (document.all){


          if (event.keyCode == 13){


           event.returnValue=false;


           event.cancel = true;


           btn.click();


          }


         }


         else if (document.getElementById){


          if (event.which == 13){


           event.returnValue=false;


           event.cancel = true;


           btn.click();


          }


         }


         else if(document.layers){


          if(event.which == 13){


           event.returnValue=false;


           event.cancel = true;


           btn.click();


          }


         }


        }


        function port4000reboot()
         {
         var answer = confirm("Do you want to reboot the player " + document.getElementById("playerIP").value + " ?")
         if (answer)
         MyObject.run ("file:///C:/Batches/port4000.lnk" + " " + document.getElementById("playerIP").value);
         else
         alert ("Reboot aborted!")
         }

        function RDP()
         {
         var addy=document.getElementById("serverIP").value;
         MyObject.run ("file:///C:/Windows/System32/cmdkey.exe /generic:" + addy + " /user:removedforsecurity /pass:removedforsecurity");
         MyObject.run ("file:///C:/Windows/System32/mstsc.exe" + " /v " + addy); 
         }

        function contentBox()
         {
         MyObject.run ("file:///C:/Windows/System32/mstsc.exe" + " /v removedforsecurity");
         }

        function serverPing()
         {
         MyObject.run ("file:///C:/Batches/WebPort4000.bat" + " " + document.getElementById("serverIP").value);
         }

        function playerPing()
         {
         MyObject.run ("file:///C:/Batches/pinging.lnk" + " " + document.getElementById("playerIP").value);
         }

        function refreshReboot()
         {
         var answer = confirm("Do you want to delete all content on " + document.getElementById("playerIP").value)
         if (answer)
         MyObject.run ("file:///C:/Batches/RefreshReboot.lnk" + " " + document.getElementById("playerIP").value);
         else
         alert ("Delete Aborted!")
         }

        function VPNtest()
         {
         MyObject.run ("file:///C:/Batches/VPNtest.lnk");
         }

        function outPing()
         {
         MyObject.run ("file:///C:/Batches/outping.lnk");
         }



        function trackUPS()
         {
         var tURL='http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&error_carried=true&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en-us&InquiryNumber1=' + document.getElementById("tracking").value + '&AgreeToTermsAndConditions=yes';

         window.open(tURL);
         }

        function trackFedEx()
         { 
         var tURL="http://www.fedex.com/Tracking?cntry_code=us&tracknumbers=" + document.getElementById("tracking").value;
         window.open(tURL);
         }

        </script>

        <!-- no script -->
        <noscript>Please allow blocked content/enable javascript in your browser.</noscript>

    </head>

    <body>

        <!-- container -->
        <div id="container">

            <!-- topbar -->
            <div id="topbar">

                <h1>OSA Dev Tool 2.0</h1>

            </div>

            <!-- main tools -->
            <div id="maintools" class="clearfix">

                <!-- player tools -->
                <div id="playertools">

                <form action="javascript:playerPing()">

                    <h2>Player Tools</h2>

                    <h3>Player IP Address:</h3>

                    <input type="text" id="playerIP" placeholder="IP Address" maxlength="15" />

                    <br />

                    <button id="pingButton" onclick="playerPing()">Continuous Ping</button>

                    <br />

                    <button id="rebootButton" onclick="port4000reboot()">Port 4000 Reboot</button>

                    <br />

                    <button id="refreshButton" onclick="refreshReboot()">Refresh Content/Reboot</button>

                </form>

                </div>

                <!-- server tools -->
                <div id="servertools">

                <form action="javascript:RDP()">

                    <h2>Server Tools</h2>

                    <h3>Server IP Address:</h3>

                    <input type="text" id="serverIP" placeholder="IP Address" maxlength="15" />

                    <br />

                    <button id="pingButton1" onclick="serverPing()">Continuous Ping</button>

                    <br />

                    <button id="rdpButton" onclick="RDP()">RDP</button>

                    <br />

                    <button id="contentButton" onclick="contentBox()">RDP To RMS</button>

                </form>

                </div>

                <!-- tracking -->
                <div id="idtracking">

                <form action="javascript:trackUPS()" >

                    <h2>Tracking</h2>

                    <h3>Tracking Number:</h3>

                    <input type="text" id="tracking" placeholder="Tracking #" maxlength="26" />

                    <br />

                    <button onclick="trackUPS()">UPS</button>

                    <br />

                    <button onclick="trackFedEx()">FedEx</button>

                </form>

                </div>

            </div>

            <!-- secondary tools -->
            <div id="secondarytools">

                <button onclick="outPing()">Telnet to RFS to Ping</button>

                <button onclick="VPNtest()">VPN Test</button>

            </div>

            <!-- portals -->
            <div id="portals" class="clearfix">

                <h1>Portals</h1>

                <!-- rms -->
                <div id="rms">

                    <h3><a href="#">removedforsecurity</a></h3>

                    <p>
                    Username: <strong>removedforsecurity</strong>
                    <br />
                    Password: <strong>removedforsecurity</strong>

                </div>

                <!-- rms -->
                <div id="rms">


                    <h3><a href="#">removedforsecurity</a></h3>

                    <p>
                    Username: <strong>removedforsecurity</strong>
                    <br />
                    Password: <strong>removedforsecurity</strong>

                </div>

            </div>

            <footer>

                <p>
                OSA Dev Tool Revision 2.0
                <br />
                Code by: Ed
                <br />
                Template by: Bob
                <br />
                Revised by: Corey
                <br />
                Theme: Dark | <a href="OSADevToolBright.html">Bright</a>
                </p>

            </footer>

        </div>

    </body>

</html>

Keep in mind, I have changed sensitive information in the code to RMS or "Removed for Security".

I actually have not learned any Javascript yet. I literally copied and pasted his script element to the new web design and added the same syntax in the buttons and the inputs. I also added the same IDs to what I thought appropriate.