Solved

Using javascript switch and need to use <ahref on actions

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Bloated registry! 29 569
How to genarate PDF with html+css 5 41
javascript issues 2 81
Group Policy Object - Mapping DrivesI'v 5 49
Goal:  To set up a secure SSH server for your home computer to make it accessible anywhere AND to use it as a port forwarding proxy. Steps 1.  WinSSHD version 5 is free for personal use.  So download and install it.  You can download it from the…
Preface There are many applications where some computing systems need have their system clocks running synchronized within a small margin and eventually need to be in sync with the global time. There are different solutions for this, i.e. the W3…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

16 Experts available now in Live!

Get 1:1 Help Now