Link to home
Start Free TrialLog in
Avatar of skinnz_2000
skinnz_2000

asked on

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

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 %>
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

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
This is server side code you're looking for, right? This won't work client side.

Fritz the Blank
Avatar of Antithesis
Antithesis

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.
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" -->
note this thread should have gone under the asp section..
as most of the ppl here are more familiar and targetting client side javascript
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" -->
Avatar of skinnz_2000

ASKER

Hey sh0e, how come it doesn't work under Netscape?
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
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?
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
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?
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
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?
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..
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
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
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.  
>>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
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
i dont understand why you had problems with my example
hm.. as long as the problem has been solved i guess
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
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
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
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
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