Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HTML5 show querystrings and if else statements

Posted on 2014-04-07
17
Medium Priority
?
972 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
[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
  • 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
Technology Partners: 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 53

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 53

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 53

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 53

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 53

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 53

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 53

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 53

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

660 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