Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HTML5 show querystrings and if else statements

Posted on 2014-04-07
17
Medium Priority
?
1,065 Views
Last Modified: 2014-04-27
I'm moving away from ASP pages and going to HTML5 pages.  I alway put these 3 lines of code first in my ASP pages:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


Now in HTML5 looks like this, one single line:
<!doctype html>


When using vbscript in my html code I used to do something like this below to show passed variables and do if else statements.  How do I get my vbscript to work on my HTML5 page or what alternative do I have?

<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>
   Album: <%=Request.QueryString("p_heading")%>

   <% If Request.QueryString("p_gallery") = "01" Then %>
      <li><img src="test1.gif" /></li>
      <li><img src="test2.gif" /></li>
   <% Else %>
      <li><img src="test1.gif" /></li>
      <li><img src="test2.gif" /></li>
   <% End If %>
</td>
</tr>
</table>



Sample code or link to samples needed.

Regards,
Torrey
0
Comment
Question by:Torrey Bates
  • 8
  • 5
  • 4
17 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39984792
You still need <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> at the top of the page to tell the server what you are doing.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39984794
This page http://www.w3schools.com/asp/default.asp does not show the VBSCRIPT declaration but you may need it anyway to set the 'codepage'.
0
 
LVL 2

Author Comment

by:Torrey Bates
ID: 39984819
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!doctype html>

When I do that the <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> and view in a browser it literally prints it.

Regards,
Torrey
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39984872
Your asp code will worth with HTML5, HTML4 or XHTML.    The HTML 5 version is below.  If you have not used Classic ASP in a while and this is a new server, are you sure Classic ASP is turned on?  
http://www.iis.net/learn/application-frameworks/running-classic-asp-applications-on-iis-7-and-iis-8/classic-asp-not-installed-by-default-on-iis


<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Test</title>
</head>
<body>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>
   Album: <%=Request.QueryString("p_heading")%>

   <% If Request.QueryString("p_gallery") = "01" Then %>
      <li><img src="test1.gif" /></li>
      <li><img src="test2.gif" /></li>
   <% Else %>
      <li><img src="test1.gif" /></li>
      <li><img src="test2.gif" /></li>
   <% End If %>
</td>
</tr>
</table> 
</body>
</html>

Open in new window

0
 
LVL 2

Author Comment

by:Torrey Bates
ID: 39984910
Scott,

Double checked the link you provided and my classic ASP is installed on my local test and host Servers.

If I take your code sample and view in IE, Google Chrome, or Safari - it completely bypasses the vbscript code and prints everything in the <% %> on the web page, the actually code.

If I rename the code sample file from .html to .asp then it works BUT I need to keep my files .html

Regards,
Torrey
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39984988
Are you sure your local webserver is running?    You can run local.html pages with or without the webserver running.  

Are you sure you are in the localhost path?  If you create a simply file called "hello.html" and put any text in the file, save it.  Then http://localhost/hello.html can you view the file?  Same with asp, you have to surf to it http://localhost/Test.asp 

Do you need to add a port to your localhost url?  http://locahost:1234/test.asp
0
 
LVL 2

Author Comment

by:Torrey Bates
ID: 39985010
Scott,

Yes - local webserver running.

If I stop the local testing webserver then I get page cannot be displayed when trying to view in browser any html or asp pages that I'm testing with the http://localhost/{page name}.

Also using the "localhost" in the path.  All other html pages work fine this site.  Just the one trying to use vbcsript doesn't process it unless I rename the file from .html to .asp which I want to get away from ASP pages.  I get the same results on the live paid hosting company Server.

Regards,
Torrey
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39985079
OHHH, I understand now.  You want to use asp code inside of a .html page.
0
 
LVL 2

Author Comment

by:Torrey Bates
ID: 39985086
Scott,

Yes - since I'm moving from .asp pages to .html pages I need a way to simply show querystring variables or do a if/else/then statement.

Knowing vbscript is the default language in active server pages can vbscript be used on HTML5 pages somehow?  If not, how do people coding in HTML5 handle these tasks?  I can't be the only one wanting to show querystring variables or want to do if/else/then statements.

Regards,
Torrey
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39985109
See if this works.

I have tried a few things on my local machine and no luck but trying this one now.

http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Q_27531603.html#a37418478
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39985118
You can  have html5 in your .asp page.  Remember that vbscript runs on the server.  

If you have the following code below, when you run the page and view source, all you see is html 5.  
First, all the asp/vb is run on the server.  
Next, any html generated by asp/vb along with the page html is rendered in the browser at the same time.
Finally, any javascript is run.
When you view source, it looks like it is all at once because it happens so fast. The end result is an html5 page.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Test</title>
</head>
<body>
<%
theHTML = "<h1>Hello World</h1>
theHTML=theHTML&"<p>This runs on the server</p>

%>
<p>I am run locally</p>
<p id="test"></p>
<script> 
var p = document.getElementById("test");
p.appendChild(document.createTextNode("Some random text."));
 </script>
</body>
</html>

Open in new window

0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39985120
>Moving away from asp.  

What you are doing is not moving away from asp.  You are just allowing asp to use the html extension.
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39985135
I tested that solution and it worked.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39985325
If you are using VBScript in your pages, you are virtually by definition using ASP (Active Server Pages).  Running pages with a *.html extension thru the ASP interpreter does not change that.  ASP and HTML are simply two different things that can work together.  It does not matter which version of HTML you are generating.
0
 
LVL 2

Author Comment

by:Torrey Bates
ID: 39986109
Scott,

Like I said in initial post,  "I'm moving away from ASP pages and going to HTML5 pages."

Others have to be doing what I want to do somehow without keeping, making or tricking anything to make an HTML page think or run like it's an ASP page.  One day I will run into a host that doesn't support classic ASP and I'm not going to deal with that.

Regards,
Torrey
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39986549
If you run into a host that does not support Classic ASP, your VBscript will not run at all.  As long as you are using VBscript in your pages, you are Not moving away from Classic ASP.  Note that if you move to ASP.NET, the newer version, the file extension will be '*.aspx', not '*.html'.  The important point is that you are using server side language.  For 'plain' HTML5, you can't use any server side language.
0
 
LVL 54

Accepted Solution

by:
Scott Fell,  EE MVE earned 1400 total points
ID: 39986684
>Like I said in initial post,  "I'm moving away from ASP pages and going to HTML5 pages."

You may have missed my previous comment http:#a39985120 and Dave reiterated very nicely http:#a39986549 

Currently Classic ASP is supported by windows server 2012.  The end of life is scheduled for 2023 http://support.microsoft.com/lifecycle/search/default.aspx?sort=PN&alpha=Windows+Server&Filter=FilterNO

Using HTML5 or XHTML as I explained has little to do with what serverside language you use.  You can move away from HTML4 to HTML5, but using asp and vbscript will have little to do with that as I explained because the code generated is on the server, then sent to the browser along with the html after which any js is run.

If your real concern is a webhost not supporting asp in the future, I suggest learning PHP.  PHP will resemble classic asp more than .NET.   You can still use MS SQL Server with PHP as well as MySQL and  20 other databases http://www.php.net/manual/en/refs.database.vendors.php  http://www.codecademy.com/learn
0

Featured Post

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!

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

876 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