0

I am trying for the life of me to make tabs work in my HTA. If anyone can spot the error here that would be awesome. It says im getting an undefined variable when I launch. Below is my code for the HTA. Im not sure exactly where the error is coming from. I believe it has to do with my "panels" in the javascript..

<HTML>
<HEAD>
<HTA:APPLICATION 
   ID="AccessPortal" 
   APPLICATIONNAME="AccessPortal"
   Border = "thin"
   BorderStyle = "normal"
   Caption = "yes"
   InnerBorder="no"
   MaximizeButton = "no"
   MinimizeButton = "yes"
   Navigable="yes"
   Scroll="yes"
   Selection="yes"
   ShowInTaskBar = "yes"
   SingleInstance = "yes"
   SysMenu = "yes"
   Version = "1.0"
/>
<TITLE>Access Portal</TITLE> 
<link rel="stylesheet" type="text/css" href="css/style.css"> 
<!-- Window resize VBS -->
<SCRIPT LANGUAGE="VBScript">


    Sub Window_onLoad
        window.resizeTo 1100,625
    End Sub 

</SCRIPT>
<!-- Get username for print -->
<SCRIPT Language="VBScript">
Sub GetUserName()
    Set WshNetwork = CreateObject("WScript.Network")
    'Now simply grab the user's windows loginID and 
    'save to variable GetUser to use later in pasting
    Dim GetUser
    GetUser = WshNetwork.UserName 
    Set WshNetwork = Nothing
    user.innerHTML = GetUser
End Sub
</SCRIPT>
<!-- Establish Excel Communication -->
<SCRIPT Language="VBScript">  
Sub TallySportsBottle()
curDate = now
Dim oXLApp, wb, ws

'~~> Define xlUp
Const xlUp = -4162

Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Visible = True

Set objWorkbook = objExcel.Workbooks.Open("C:\Users\Gloria Vena\Desktop\new2\Excel\Access Portal Issues Report.xlsx")
Set ws = objWorkbook.Worksheets(1)

With ws
    lastRowIndex = .Cells(.Rows.Count, "A").End(xlUp).row
    .Cells(lastRowIndex + 1, 1) = curDate
End With

objExcel.ActiveWorkbook.Save 
objExcel.ActiveWorkbook.Close

objExcel.Application.Quit
End Sub


</SCRIPT>
<script language="JavaScript"> //message of the day
// This variable contains the path and filename of the MOTD text file.
// Make sure to type '\\' for each '\'; e.g. \\\\server\\share\\file
// If you specify only a filename without a preceding path, the HTA
// will look for the file in the same directory as the HTA.
var MESSAGE_FILE_NAME = "MOTD.txt";

// This function executes when the body has finished loading.
function executeApp()
{
  var fso, appdir, messagefile, ts, messagetext, line;

  fso = new ActiveXObject("Scripting.FileSystemObject");

  // If the MESSAGE_FILE_NAME doesn't contain a path, assume it's
  // in the same directory as this HTA.
  if (MESSAGE_FILE_NAME.indexOf("\\") == -1) {
    // Use unescape in case the application's path contains spaces.
    appdir = unescape(fso.GetParentFolderName(location.pathname));
    messagefile = fso.BuildPath(appdir, MESSAGE_FILE_NAME);
  }
  else {
    messagefile = MESSAGE_FILE_NAME;
  }

  try {
    // Open the message-of-the-day file as a TextStream.
    ts = fso.OpenTextFile(messagefile, 1);
    messagetext = "";
    while (! ts.AtEndOfStream) {
      line = ts.ReadLine();
      // If the line contains text, enclose in <p> element;
      // otherwise, construct a blank line with a nonbreaking space.
      if (line.length > 0)
        line = line.replace(/^(.*)$/, "$1");
      else
        line = "<p>&nbsp;</p>";
      messagetext += line;
    }
    ts.Close();
  }
  // Construct an error message if an error occurred.
  catch(err) {
    messagetext = "<p>Can't display the message of the day.</p>"
      + "<p>&nbsp;</p>"
      + "<p>Error <b>0x" + hex(err.number) + "</b><br />"
      + err.description + "</p>";
  }

  // Update the innerHTML element of the textarea element with the
  // message text.
  document.getElementById("MessageText").innerHTML = messagetext;

  // Use the line of code below to automatically close the HTA
  // after a specified number of milliseconds.
  // window.setTimeout("window.close();", 30000);
}
</script>
<script type="text/javascript"> //tab control js
var panels = new Array("","panel1","panel2","panel3","panel4","panel5");
function panel(tab) {
    for (i=1; i<panels.length; i++) {
        if (i == tab) {
            document.getElementById("tab"+i).className = "tabs tabs1";
            document.getElementById("panel"+i).style.display = "block";
        } else {
            document.getElementById("tab"+i).className = "tabs tabs0";
            document.getElementById("panel"+i).style.display = "none";
        }
    }
}
</script>
<!-- TAB CSS -->
<style type="text/css">
.tabs {
  border-collapse: collapse;
  color: black;
  cursor: pointer;
  cursor: hand;
  font-family: arial;
  font-size: 9pt;
  font-weight: bold;
  margin-top: 4px;
  padding: 2px 4px 0px 4px;
  position: relative;
  text-align: center;
  text-decoration: none;
  z-index: 1;
}
.tabs0 {
  background-color: wheat;
  border: solid 1px black;
}
.tabs1 {
  background-color: white;
  border-color: black black white black;
  border-style: solid solid solid solid;
  border-width: 1px 1px 1px 1px;
}
</style>
</HEAD>
<body onload="executeApp()"> 
 <div align="center" class="container">
  <div class="header">
   <div class="h_logo">
    <img src="img/Logo.jpg" width="148px" height="80px"></>
   </div>
   <div class="h_text">
    Access Portal
   </div>
   <br />
   <div class="TopMenu">
    <ul>
     <li><span class="tabs tabs1" id="tab1" onclick="panel(1)">Tab1</span></li>
     <li><span class="tabs tabs1" id="tab1" onclick="panel(2)">Tab2</span></li>
     <li><span class="tabs tabs1" id="tab1" onclick="panel(3)">Tab3</span></li>
     <li><span class="tabs tabs1" id="tab1" onclick="panel(4)">Tab4</span></li>
     <li><span class="tabs tabs1" id="tab1" onclick="panel(5)">Tab5</span></li>
    </ul>
    <br />
   </div>
  </div>
  <div class="pagecontent">
  <div class="panel" id="panel1" style="display:block">
   <span class="header1">Hello, <span id="user">Name</span>!</span>
   <br />
   <span class="text1">Please  select which program you wish to launch.</span>
   <div class="LeftContainer">
    <div class="appMenu">
     <ul>
      <li><a href="#">Open All Programs</a></li>
      <li><a href="#">Manager</a></li>
      <li><a href="#">Capture</a></li>
      <li><a href="#">Manager2</a></li>
      <li><a href="#">Website</a></li>
      <li><a href="#">Suite</a></li>
      <li><a href="#">Service</a></li>
      <li><a href="#">Co</a></li>
      <li><a href="#">Microsoft Outlook</a></li>
     </ul>
   </div>
   </div>
   <div class="RightContainer">
    <div class="RightBox">
     <span class="header1">Important Information:</span>
     <br />
     <div class="MessageBox">
      <span id="MessageText"></span> 
     </div>
    </div>
    <div class="botBox">
     <a class="button green" href="#" onclick="TallySportsBottle()">+1</a>
    </div>
   </div>
  </div> 
  <br/>
    <div class="panel" id="panel2" style="display:hidden">
   <span class="header1">Hello, <span id="user">Name</span>!</span>
   <br />
   <span class="text1">Please  select which program you wish to launch.</span>
   <div class="LeftContainer">
    <div class="appMenu">
     <ul>
      <li><a href="#">Open All Programs</a></li>
      <li><a href="#">Manager</a></li>
      <li><a href="#">Capture</a></li>
      <li><a href="#">Manager2</a></li>
      <li><a href="#">Website</a></li>
      <li><a href="#">Suite</a></li>
      <li><a href="#">Service</a></li>
      <li><a href="#">Co</a></li>
      <li><a href="#">Microsoft Outlook</a></li>
     </ul>
   </div>
   </div>
   <div class="RightContainer">
    <div class="RightBox">
     <span class="header1">Important Information:</span>
     <br />
     <div class="MessageBox">
      <span id="MessageText"></span> 
     </div>
    </div>
    <div class="botBox">
     <a class="button green" href="#" onclick="TallySportsBottle()">+1</a>
    </div>
   </div>
  </div>  
  <br/>
    <div class="panel" id="panel3" style="display:hidden">
   <span class="header1">Hello, <span id="user">Name</span>!</span>
   <br />
   <span class="text1">Please  select which program you wish to launch.</span>
   <div class="LeftContainer">
    <div class="appMenu">
     <ul>
      <li><a href="#">Open All Programs</a></li>
      <li><a href="#">Manager</a></li>
      <li><a href="#">Capture</a></li>
      <li><a href="#">Manager2</a></li>
      <li><a href="#">Website</a></li>
      <li><a href="#">Suite</a></li>
      <li><a href="#">Service</a></li>
      <li><a href="#">Co</a></li>
      <li><a href="#">Microsoft Outlook</a></li>
     </ul>
   </div>
   </div>
   <div class="RightContainer">
    <div class="RightBox">
     <span class="header1">Important Information:</span>
     <br />
     <div class="MessageBox">
      <span id="MessageText"></span> 
     </div>
    </div>
    <div class="botBox">
     <a class="button green" href="#" onclick="TallySportsBottle()">+1</a>
    </div>
   </div>
  </div>  
  <br/>
    <div class="panel" id="panel4" style="display:hidden">
   <span class="header1">Hello, <span id="user">Name</span>!</span>
   <br />
   <span class="text1">Please  select which program you wish to launch.</span>
   <div class="LeftContainer">
    <div class="appMenu">
     <ul>
      <li><a href="#">Open All Programs</a></li>
      <li><a href="#">Manager</a></li>
      <li><a href="#">Capture</a></li>
      <li><a href="#">Manager2</a></li>
      <li><a href="#">Website</a></li>
      <li><a href="#">Suite</a></li>
      <li><a href="#">Service</a></li>
      <li><a href="#">Co</a></li>
      <li><a href="#">Microsoft Outlook</a></li>
     </ul>
   </div>
   </div>
   <div class="RightContainer">
    <div class="RightBox">
     <span class="header1">Important Information:</span>
     <br />
     <div class="MessageBox">
      <span id="MessageText"></span> 
     </div>
    </div>
    <div class="botBox">
     <a class="button green" href="#" onclick="TallySportsBottle()">+1</a>
    </div>
   </div>
  </div>  
  <br/>
    <div class="panel" id="panel5" style="display:hidden">
   <span class="header1">Hello, <span id="user">Name</span>!</span>
   <br />
   <span class="text1">Please  select which program you wish to launch.</span>
   <div class="LeftContainer">
    <div class="appMenu">
     <ul>
      <li><a href="#">Open All Programs</a></li>
      <li><a href="#">Manager</a></li>
      <li><a href="#">Capture</a></li>
      <li><a href="#">Manager2</a></li>
      <li><a href="#">Website</a></li>
      <li><a href="#">Suite</a></li>
      <li><a href="#">Service</a></li>
      <li><a href="#">Co</a></li>
      <li><a href="#">Microsoft Outlook</a></li>
     </ul>
   </div>
   </div>
   <div class="RightContainer">
    <div class="RightBox">
     <span class="header1">Important Information:</span>
     <br />
     <div class="MessageBox">
      <span id="MessageText"></span> 
     </div>
    </div>
    <div class="botBox">
     <a class="button green" href="#" onclick="TallySportsBottle()">+1</a>
    </div>
   </div>
  </div>  
  <br/>

  </div>
 </div>
</body>
</HTML>
Dan Brookwell
  • 341
  • 2
  • 12
  • Dare to tell us the name of the undefined variable? Notice, that all `li`s in `.TopMenu` have the same `id` (`tab1`), however, you're referring `tab1`, `tab2` etc. – Teemu Aug 08 '15 at 09:13
  • Use number.toString(16) to convert a number to hex. hex isn't a valid function. See http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript for the different conversion methods – cup Aug 09 '15 at 16:24

0 Answers0