473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

switch statement is driving me crazy



Every time the function below is called I get the alert. So I put a
deliberate error in there and I check the value of
(reportType=='MANDATE') in Firebug, which is found to be true. But
still the alert comes up. Why?
I checked the following watch expressions at the blah blah point.

id = 5843
reportType = "MANDATE"
(reportType=='MANDATE') = true

It is being called like so:

showReport(5843,'MANDATE');

So what is going on here? Please let me in on the secret of writing a
switch statement.
function showReport(id, reportType, bHighlightRow)
{
var url;
switch (reportType) {
case 'INVESTOR':
url = 'getFundProfile.aspx?Ref='
break
case 'SUMMARY':
url = 'getprofile.aspx?Summary='
break
case 'MANDATE':
url = 'getprofile.aspx?Ref='
break
default:
alert('Error - javascript:showReport() called with wrong args')
}

blah blah;

}
Dec 14 '07 #1
5 1736
mark4asp wrote:
Every time the function below is called I get the alert. So I put a
deliberate error in there and I check the value of
(reportType=='MANDATE') in Firebug, which is found to be true. But
still the alert comes up. Why?
I just tried this and it alerts Mandate on IE and FF2.

<html><body>
<script language="javascript">
function showReport(id, reportType, bHighlightRow)
{
var url;
switch (reportType) {
case 'INVESTOR':
alert("Investor")
break
case 'SUMMARY':
alert("Summary")
break
case 'MANDATE':
alert("Mandate")
break
default:
alert('default')
}
}
showReport(5843,'MANDATE');
</script></body></html>

Is your code being compressed/minified and the lack of semi-colons is
catching you out? Although I would expect Firefox to be very verbose
about it in the Error Console if that were the case.
Dec 14 '07 #2
VK
switch statement is driving me crazy

switch statement implements fall-through branching as opposed to the
exclusive branching implemented by if-else if-else statement. That
means that switch executes the branch where the condition is true and
all branches below that branch without further condition check. If you
want exclusive branching then use the right statement for that: if-
else if-else. If switch statement is too appealing to you, then add
break; statement at the end of each branch:

switch (condition) {
case 1 : statements;
break;
case 2 : statements;
break;
case 3 : statements;
break;
default: statements;
}
Dec 14 '07 #3
Lee
VK said:
>
>switch statement is driving me crazy

switch statement implements fall-through branching as opposed to the
exclusive branching implemented by if-else if-else statement. That
means that switch executes the branch where the condition is true and
all branches below that branch without further condition check. If you
want exclusive branching then use the right statement for that: if-
else if-else.
Actually, the switch statement is the correct choice when you
are comparing a variable against a number of literal values.
--

Dec 14 '07 #4
On Dec 14, 11:22 am, "mark4asp" <mark4...@gmail.comwrote:
id = 5843
reportType = "MANDATE"
(reportType=='MANDATE') = true

It is being called like so:

showReport(5843,'MANDATE');

So what is going on here? Please let me in on the secret of writing a
switch statement.

function showReport(id, reportType, bHighlightRow)
{
var url;
switch (reportType) {
case 'INVESTOR':
url = 'getFundProfile.aspx?Ref='
break
case 'SUMMARY':
url = 'getprofile.aspx?Summary='
break
case 'MANDATE':
url = 'getprofile.aspx?Ref='
break
default:
alert('Error - javascript:showReport() called with wrong args')
}

blah blah;

}- Hide quoted text -

- Show quoted text -
It works for me also. Can you post the rest of the script or a link?

Dec 14 '07 #5
VK said the following on 12/14/2007 12:39 PM:
>switch statement is driving me crazy

switch statement implements fall-through branching as opposed to the
exclusive branching implemented by if-else if-else statement. That
means that switch executes the branch where the condition is true and
all branches below that branch without further condition check.
Not entirely true. It will execute through branches until it encounters
either the end of the switch, or, a return statement. The OP's code has
the return statements (check it again).

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 14 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
2
by: Grant Stanley | last post by:
I'm writing a database client program in C#, and it accesses a MS SQL V7 database. In one part of my program I am using a SqlCommand class to run a SQL Statement, the command text uses parameters,...
0
by: Shapper | last post by:
Hello, I have this code in Global.asax: Sub Session_Start(Sender As Object, E As EventArgs) Dim cookie As HttpCookie = Request.Cookies("MyCookie") If Not cookie Is Nothing Then...
1
by: Miguel Dias Moura | last post by:
Hello, I have been trying, for days, to retrieve a control's ClientId in a javascript function. I am using a master page and this is why I need to retrieve the Control's ClientId. The control...
19
by: momo | last post by:
Can someone tell me why my query returns nothing? "Select EmployeeID, SSN, LastName, FirstName, Address, City, State, Zipcode, Phone from Employee where MiddleName ='' " However this works...
5
by: Pupeno | last post by:
Hello, I am experiencing a weird behavior that is driving me crazy. I have module called Sensors containing, among other things: class Manager: def getStatus(self): print "getStatus(self=%s)"...
3
by: rashpal.sidhu | last post by:
Please help, this problem is driving me crazy !! I am using metaphone to create phonetic keys. When i run the module stand-a-lone it works fine. I'm trying to create a runner for informix...
5
by: power2005 | last post by:
Hi Experts I'm having a problem with IIf statement and it's driving me crazy... i'm a total newbie and i've spent hours to make it work but to no avail... what I'm trying to do is to have a...
2
by: kheitmann | last post by:
OK, so I have a blog. I downloaded the "theme" from somewhere and have edited a few areas to suit my needs. There are different font themes within the page theme. Long story short, my "Text Posts"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.