Solved

Using javascript switch and need to use <ahref on actions

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Have you ever stumbled upon a software that is so great that you just love? It happened to me. Love at first sight. Filezilla Server.   Ok its not the most advanced ftp server I've came across. But its a fairly simple piece of software to get the …
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now