Solved

Using javascript switch and need to use <ahref on actions

Posted on 2010-08-26
4
425 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
  • 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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…
If, like me, you have a lot of Dell servers in the estate you manage this article should save you a little time. When attempting to login to iDrac on any server I would be presented with two errors. The first reads "Do you want to run this applicati…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

679 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