?
Solved

Translation VBScript to Javascript for Selct Case with Request.querystring 75 points is all I have to offer

Posted on 2003-03-15
26
Medium Priority
?
183 Views
Last Modified: 2012-05-04
Hi, Can anyone tell me how to write the Javascript for the following VBscript.
I assume I have to use a Switch command. 75 Points is all I have to offer. Thanks!!

<A HREF='/ruffwear/products/categories.asp?Category=Bowls'>Bowls</A>

<% SELECT CASE Request.querystring("Category") %>
<%   CASE "Bowls" %>
<!--#include virtual="/ruffwear/ssi/bowls.ssi" -->
<%   CASE "Coats" %>
<!--#include virtual="/ruffwear/ssi/coats.ssi" -->
<%   CASE "Toys" %>
<!--#include virtual="/ruffwear/ssi/toys.ssi" -->
<% END SELECT %>
0
Comment
Question by:skinnz_2000
[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
  • 11
  • 7
  • 7
  • +1
26 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8143067
Something like:

strCategory = Request.querystring("Category")
switch (strCategory ) {
   case "Bowls" :
      document.write("<!--#include virtual='/ruffwear/ssi/bowls.ssi' -->");
      break;
   case "Coats" :
      document.write("<!--#include virtual='/ruffwear/ssi/coats.ssi' -->");
      break;
   case "Toys" :
      document.write("<!--#include virtual='/ruffwear/ssi/toys.ssi' -->");
      break;
   default :
      //You can put what you want here;
}


Fritz the Blank
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8143072
This is server side code you're looking for, right? This won't work client side.

Fritz the Blank
0
 
LVL 1

Expert Comment

by:Antithesis
ID: 8144859
Yeah, the #include commands would be inserted after the page was generated by the server, rendering them useless.  You'd need to use PHP or another server-side language.
0
Industry Leaders: 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 16

Expert Comment

by:sh0e
ID: 8145344
server side javscript asp code using if statements:

<%@ Language="Javascript" %>

<% strCategory=Request.querystring("Category") %>
<% if(strCa=="Bowls") %>
<!--#include virtual="/ruffwear/ssi/bowls.ssi" -->
<% if(strCa=="Coats") %>
<!--#include virtual="/ruffwear/ssi/coats.ssi" -->
<% if(strCa=="Toys") %>
<!--#include virtual="/ruffwear/ssi/toys.ssi" -->
0
 
LVL 16

Expert Comment

by:sh0e
ID: 8145350
note this thread should have gone under the asp section..
as most of the ppl here are more familiar and targetting client side javascript
0
 
LVL 16

Expert Comment

by:sh0e
ID: 8145433
crap i realized that i forgot something.. and my code is nonworking :p
i got lazy and cut down the variable name.. but forgot to put it back when i was done :D

<%@ Language="Javascript" %>

<% strCategory=Request.querystring("Category") %>
<% if(strCategory=="Bowls") %>
<!--#include virtual="/ruffwear/ssi/bowls.ssi" -->
<% if(strCategory=="Coats") %>
<!--#include virtual="/ruffwear/ssi/coats.ssi" -->
<% if(strCategory=="Toys") %>
<!--#include virtual="/ruffwear/ssi/toys.ssi" -->
0
 

Author Comment

by:skinnz_2000
ID: 8146217
Hey sh0e, how come it doesn't work under Netscape?
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8146514
Hang on here,

There is no reason why you can't use the switch statement with server side javascript. The question was to replace VBScript syntax with JavaScript syntax, and my post does that.

Now what do you mean this won't work with Netscape?

Fritz the Blank
0
 

Author Comment

by:skinnz_2000
ID: 8146615
Hey Fritz, easy. I couldn't get yours to work with either one and the other one did work but not with Netscape, only with IE. Maybe I just can't get your code to work and your answer is good, but how should I know that if I can't get it to work. Catch 22. Do I need Script tags?
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8146632
Let's go back to my question about where you are running this. Is this client side or server side code?

>>Hey Fritz, easy.

How easy do you want me to take this....


Fritz the Blank
0
 

Author Comment

by:skinnz_2000
ID: 8146634
Hey Fritz, easy. I couldn't get yours to work with either one and the other one did work but not with Netscape, only with IE. Maybe I just can't get your code to work and your answer is good, but how should I know that if I can't get it to work. Catch 22. Do I need Script tags?
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8146654
Here is a working example for you to look at:

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function showSelection(intSelected){
     switch (intSelected) {
       case 1 :
          alert("Keeps the doctor away!");
          break;
       case 2 :
          alert("Florida loves you!");
          break;
       case 3 :
          alert("On your way to being a code monkey!");
          break;
       default :
          alert("It would help if you picked something!");
       }
}
//-->
</SCRIPT>


</HEAD>
<BODY>

<FORM action="" method=POST id=form1 name=form1>
<SELECT id=select1 name=select1 onChange=showSelection(this.selectedIndex)>
     <OPTION></OPTION>
     <OPTION>Apples</OPTION>
     <OPTION>Oranges</OPTION>
     <OPTION>Bananas</OPTION>
</SELECT>

</FORM>
</BODY>
</HTML>


Fritz the Blank
0
 

Author Comment

by:skinnz_2000
ID: 8146660
Hey Fritz, easy. I couldn't get yours to work with either one and the other one did work but not with Netscape, only with IE. Maybe I just can't get your code to work and your answer is good, but how should I know that if I can't get it to work. Catch 22. Do I need Script tags?
0
 
LVL 16

Expert Comment

by:sh0e
ID: 8146680
ok fritz here is why yours does not work..
first of all #include statements cannot be placed within <% %> since it is not parsed as a server side include if you do so..
second of all document.write will output it as a string and the #include will never be included and will be written plaintext to the client

now.. this is server side code and has nothing to do with netscape.. which is a client side viewer
i would check that your netscape is working correctly
or that the client side code generated is netscape compatible..
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8146683
Please don't use the refresh button on your browser as it will resubmit your posts. There is a reload this question link in the upper left hand corner that you can use.

Please see my two posts above.

Fritz the Blank
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8146691
shOe,

If you look at my second post, that is the question that I am getting at here. If this is going to be server-side code, it will be browser independant.

I am just trying to show to start how to write a case statement if JavaScript as the question asked. As for getting it to work for the exact application that skinnz_2000  needs, that is the next step.

Fritz the Blank
0
 

Author Comment

by:skinnz_2000
ID: 8146703
Sorry, but you sounded a bit aggressive.

Server Side.

I can get it to work with a form but not from a link, as in my example. Worked great with VB, but not with JavaScript.  The link sends the user to the asp and there should be decided which page to send back.  
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8146728
>>Sorry, but you sounded a bit aggressive.

Wow, asking for free advice with an attitude!!!!


Let's take this one step at a time:

1) Do you see how the JavaScript equivalent to the case statement is the switch statement?

2) Are you trying to move from serverside VBScript to serverside JavaScript

3) If the latter, then I don't know why there should be any browser specific issues.

Fritz the Blank
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 225 total points
ID: 8146738
This might work, but I haven't tested:

<%strCategory = Request.querystring("Category")
switch (strCategory ) {
  case "Bowls" :%>
     <!--#include virtual='/ruffwear/ssi/bowls.ssi' -->
     <%break;
  case "Coats" :%>
     <!--#include virtual='/ruffwear/ssi/coats.ssi' -->
     <%break;
  case "Toys" :%>
     <!--#include virtual='/ruffwear/ssi/toys.ssi' -->
     <%break;
  default :
     //You can put what you want here;%>
}


Fritz the Blank
0
 

Author Comment

by:skinnz_2000
ID: 8146754
1) Yeah that is clear
2) Yes
3) Either do I but it doesn't seem to work for me.

4) Take the points, Sorry if I was rude
0
 
LVL 16

Expert Comment

by:sh0e
ID: 8146887
i dont understand why you had problems with my example
hm.. as long as the problem has been solved i guess
0
 

Author Comment

by:skinnz_2000
ID: 8146888
Hi, either do I and to be honest the problem is still there but I think I should buy a few bokks and try again later
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8146892
I would have to play with it more, but is there a compelling reason to move over to server-side JavaScript? I find that using VBScript is often easier, and it has much more robust date handling abilities.

Fritz the Blank
0
 
LVL 16

Expert Comment

by:sh0e
ID: 8146911
im betting that your looking in the wrong place..
you appear to want cross browser compatibility
what needs to be altered is probably contained within ssi and the client code generated by those..

i think i know why now..
your ssi files most likely contain vbscript code..
so adding the <%@ Language="Javascript" %> probably botched things up
0
 
LVL 16

Expert Comment

by:sh0e
ID: 8146918
ah now i see why u want to port to javascript.. since netscape does not support vbscript
then you are definitely looking in the wrong place.. as what you are changing is the server side code
which has nothing to do with the client side browsers IE and netscape
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8146960
That's what I was wondering about above in my second post--if there was any confusion regarding what takes place client side and what takes place server side.

Fritz the Blank
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 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