Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript SWITCH is ruining my function

Posted on 2008-06-20
6
Medium Priority
?
523 Views
Last Modified: 2012-06-27
I am writing a javascript function that will open a new window with a brief bit of text based on the link they click.  The function seems to work fine unless I have the switch statement inside the function looking at the passed-in variable.  When I remove the switch statement, no problem, but when the code is there it says the function is undefined.  I'm completely at a loss for why this isn't working with the switch in place.
function Dodisplay(tneed){
	var need = tneed;
	alert(need);
	var msgText;
	var title;
	var uMonitor = "<a href='https://somelink.com/applefcu/welcome.do' class='alink'>Open New Account</a>";
	var formLink = "<a href='https://somelink2.org/form_doc.asp?rec=16' class='alink'>Dispute form</a>";
	switch(need)
	{
		case 'AccNR':
			msgText = "Due to the security restrictions we can not give out Account Numbers over our online message center. In order to obtain your Account Number please stop by any of our branch locations or fax your written and signed request to 703-555-4679.";
			title = "Account Number Reset";
			break;
		case 'OPR':
			msgText = "Due to the security restrictions we can not reset or reissue Netbranch passwords through the online message center. In order to obtain a new password please stop by any of our branch locations or contact our call center at 703-555-4800.";
			title = "Online Password Rest";
			break;
		case 'OCA':
			msgText = "<p class='hptext'>Opening a new membership account can be done by clicking here: " + uMonitor + "If you wish to open a new account under your existing membership please stop by any of our branch locations or contact our call center at 703-555-4800.</p> <p class='hptex;t'>Closing you account:<br>If you wish to close one or all of your accounts please stop by any of our branch locations or fax your written and signed request to 703-555-4679.</p>"
			title = "Opening or Closing Accounts";
			break;
		case 'TDQ':
			msgText = "<p class='hptext'>If you are disputing a transaction on your Visa Check Card please click here: " + formLink + "</p><p class='hptext'>If you are disputing a transaction on your Checking, Savings, or Money Market account please stop by any of our branch locations or contact our call center at 703-788-4800.</p>";
			title = "Transaction Disputes or Questions";
			break;
		default:
			msgText = "Your doing it wrong!";
			title "Error";
	}
	html = "<HTML><HEAD><TITLE>" + title + "</TITLE>" + "</HEAD><BODY LEFTMARGIN=0 " + "MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER>" + msgText + "</CENTER></BODY></HTML>";
	popup=window.open("","New Window",'width=530,height=605,left=400,top=250,toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0');
	popup.document.write(html);
	popup.window.focus();
	popup.document.close();
 }

Open in new window

0
Comment
Question by:Tech_maniac
[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
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
agriesser earned 320 total points
ID: 21834977
Works for me after modifying the default branch of your switch statement.
You seem to have forgotten to add a '=' in the line:

title "Error";

should read:

title="Error";
0
 
LVL 7

Expert Comment

by:Dauhee
ID: 21837359
if you go into IE options, advanced tab:
uncheck "disable script debugging"
check "display notification about every script error"

That way you will be able to see errors like that for yourself in future by looking at the bottom left of the IE status panel . .

Give a person a fish v teach then to fish :)
0
 

Author Comment

by:Tech_maniac
ID: 21846368
agriesser:
Thanks, I knew that it was something simple I was missing.  It works now, except in IE7, which I'm going through the painful process of downloading M$ visual studio to debug.  

Dauhee:
I have both of those options taken care of prior to now.  The problem with IE is the line numbers in the boxes are worthless if the script is external. As stated in the previous paragraph, I'm having to download MVS to get through this part.  

Thanks for all your help
0
Independent Software Vendors: 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!

 
LVL 14

Expert Comment

by:agriesser
ID: 21846402
There are addons for IE7 available to allow for javascript debugging, see this link:

http://www.jarrodgoddard.com/web-development/internet-explorer-7-javascript-debugging
0
 

Author Comment

by:Tech_maniac
ID: 21848688
agriesser:

I have loaded the script debugger, and got the whole thing working, but it doesn't quite work as is.  The offending line of code is where the window.open function works.  IE doesn't like the null value before the window properties. If I remove the "" and "New Window" it runs, but the size of the window isn't 530x205, and it doesn't work properly in FF after the change.  Thoughts?  I just want a small box of text explaining the disclaimer, and the cross browser thing is really #$(%*#ing  me off.
	html = "<HTML><link href='afcustyles.css' rel='stylesheet' type='text/css' /><HEAD><TITLE>" + title + "</TITLE>" + "</HEAD><BODY LEFTMARGIN='12' " + "MARGINWIDTH='12' TOPMARGIN=0 MARGINHEIGHT=0 style='background-color:#FCEFC8'><br/>" + msgText + "</BODY></HTML>";
	popup=window.open("","New Window",'width=530,height=205,left=400,top=250,toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0');
	popup.document.write(html);
	popup.window.focus();
	popup.document.close();

Open in new window

0
 
LVL 14

Assisted Solution

by:agriesser
agriesser earned 320 total points
ID: 21848894
IE is great. It refuses to create windows that have a space in the title. Don't ask me how long it took me when I tried to start my first popup window and wondered about why it didn't work on IE.

Try to call it "New_Window" and it should work fine.
0

Featured Post

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

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

It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

604 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