Solved

Using javascript switch and need to use <ahref on actions

Posted on 2010-08-26
4
427 Views
Last Modified: 2012-05-10
I am writting a large if / else tree in an existing website.  My include libraries have to be put into the html program using a scripting language called SpeedScript.  These includes bring in the login data that I am testing in my if tree.  Instead of using the if/else I am trying a switch.

I need to know how to write this if/else tree / switch statement.  I am brand new to Javascript.  Here is the code I currently have that is not working.  The actions are to open a customers indivitual Excel spreadsheet.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD>
<TITLE>eSales Center - Customer Links</TITLE>
<META HTTP-EQUIV="Cache-Control" CONTENT="No-Cache">
<META HTTP-EQUIV="Pragma" CONTENT="No-Cache">
<META HTTP-EQUIV="Expires" CONTENT="0">


<SCRIPT LANGUAGE="SpeedScript">

{shared/esalesvars.i}
{shared/validate-session.i}
{shared/pp-global.i}

assign cLogin = if trim(cLogin) = "" then get-value("operinit") else cLogin.

</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="javascript">

switch (cLogin)
{
     case "12102":
          <a href="/WI_testweb/12102.xls"><b><font size="3">Matrix</font></b></a><br />
          break
     case "134965":
          <a href="/WI_testweb/12102.xls"><b><font size="3">Matrix</font></b></a><br />
          break
     case "13953":
          <a href="/WI_testweb/12102.xls"><b><font size="3">Matrix</font></b></a><br />
          break
     case "13716":
          <a href="/WI_testweb/13716.xls"><b><font size="3">Matrix</font></b></a><br />
          break
     case "111667":
          <a href="/WI_testweb/111677.xls"><b><font size="3">Matrix</font></b></a><br />
            break
     default:
                window.alert("This account does not have a custom matrix");
 }
</SCRIPT>
</BODY>
</HTML>
0
Comment
Question by:wjindra
[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
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 33538014
Try this :

The following open the excel file in a popup window
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>eSales Center - Customer Links</TITLE>
<META HTTP-EQUIV="Cache-Control" CONTENT="No-Cache">
<META HTTP-EQUIV="Pragma" CONTENT="No-Cache">
<META HTTP-EQUIV="Expires" CONTENT="0">
<SCRIPT LANGUAGE="SpeedScript">
{shared/esalesvars.i}
{shared/validate-session.i}
{shared/pp-global.i}
assign cLogin = if trim(cLogin) = "" then get-value("operinit") else cLogin.
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="javascript">
	window.onload = function() {
		switch (cLogin) {
			case "12102":
				window.open("/WI_testweb/12102.xls","Excel");
				break;
			case "134965": 
				window.open("/WI_testweb/12102.xls","Excel");
				break;
			case "13953":
				window.open("/WI_testweb/12102.xls","Excel");
				break;
			case "13716": 
				window.open("/WI_testweb/13716.xls","Excel");
				break;
			case "111667":
				window.open("/WI_testweb/111677.xls","Excel");
				break;
			default:
				window.alert("This account does not have a custom matrix");
		}
	}
</SCRIPT>
</BODY>
</HTML>

Open in new window

0
 

Author Comment

by:wjindra
ID: 33542894
This did not work.
0
 

Accepted Solution

by:
wjindra earned 0 total points
ID: 33543961
I have now gotten my code working by using the suggestions from an different blog.  The code that works is as follows:
</SCRIPT>
</HEAD>
<BODY>

<SCRIPT type="text/javascript">
      window.onload = load;
      function load()
      {
            switch (`cLogin`)
            {
                  case 12102:
                        document.write('<a href="/WI_testweb/12102.xls"><b><font size="3">Matrix</font></b></a><br />');
                        break;
                  case 134965:
                        document.write('<a href="/WI_testweb/12102.xls"><b><font size="3">Matrix</font></b></a><br />');
                        break;
                  case 13953:
                        document.write('<a href="/WI_testweb/12102.xls"><b><font size="3">Matrix</font></b></a><br />');
                        break;
                  case 13716:
                        document.write('<a href="/WI_testweb/13716.xls"><b><font size="3">Matrix</font></b></a><br />');
                        break;
                  case 111677:
                        document.write('<a href="/WI_testweb/111677.xls"><b><font size="3">Matrix</font></b></a><br />');
                        break;
                  default:
                        window.alert(`cLogin`);
            }
      }
</SCRIPT>
</BODY>
</HTML>
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33544090
OK good, I don't understood you want to put the right link in your page
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction People like FTP.  It's a solid, stable, robust protocol for quickly transferring files between two hosts using TCP/IP.  In most cases it's much faster than SMB or CIFS, and certainly much easier to set up between organizations.  This…
Hello, As I have seen there a lot of requests regarding monitoring and reporting for exchange 2007 / 2010 / 2013 I have decided to post some thoughts together and link to articles that have helped me. Of course a lot of information you can get…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

728 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