Crap! This guy beat me to it while I was created the regular expression!! I don't know if his or my solution will work in all circumstances but here goes.
function Strip(str) {
return str.replace(/<[\w/]+[^<>]*
}
Main Topics
Browse All Topics
Hi,
I'm trying to do something like this, but I need help.
I have a table which contains Adverts for a magazine, there is a column cotaining Ad Headings. I have also stored HTML tags around the ad headings in the table. Each advert is displayed on many pages on my site.
But I want to display an ad on some pages without the HTML tags. How do I strip the html tags from the database for this page without changing the ad in each other page.
******All my code is ASP and javascript.*****
This is my code that outputs the adverts, where html tags are included.
r1 = Q("AdHead"); //Here r1 stores the ad heading with html tags
Response.Write("<td valign='top' width=400 rowspan=2>"+r1+"</td>"); //Header ok but tags included
But when I do this
r1 = Q("AdHead");
r1 = Strip(r1); //I need a strip html javascript function here
Response.Write("<td valign='top' width=400 rowspan=2>"+r1+"</td>"); //Header
Hope this makes sense.
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
oops...that was kind of sloppy of me. I'm too used to C/C++
This function works and was tested
Call it like this in your code:
r1 = RS("AdHead");
r2 = stripHTML(r1);
Response.Write("<td valign='top' width=400 rowspan=2>"+r2+"</td>");
This is the new function
function stripHTML( oldString )
{
var newString = "";
var inTag = false;
for( var i = 0; i < oldString.length; i++ )
{
if( oldString.charAt(i) == '<' ) inTag = true;
if( oldString.charAt(i) == '>' ) {
inTag = false;
i++;
}
if( !inTag ) newString += oldString.charAt(i);
}
return newString;
}
I'm still getting object expected error.
This is the function code within HTML <head>
<script language="JavaScript" type="text/javascript">
<!--
function stripHTML( oldString )
{
var newString = "";
var inTag = false;
for( var i = 0; i < oldString.length; i++ )
{
if( oldString.charAt(i) == '<' ) inTag = true;
if( oldString.charAt(i) == '>' ) {
inTag = false;
i++;
}
if( !inTag ) newString += oldString.charAt(i);
}
return newString;
}
//-->
</script>
And then I'm calling it like so inside a table within ASP tags
<%
.
.
r1 = Q("AdHead");
r2 = stripHTML(r1); //If I comment out this line I dont get an error but tags are still included.So I'm guessing it's the way the function is being called ??
Response.Write("<td>"+r1+"
.
%>
THANKS FOR ALL THE HELP SO FAR :D
Ok as I'm sure you can guess by my name I'm new to this ASP, javascript stuff. I've been messing around with it but getting now where
Here is my entire page of code can you show me where I should call the function.
Cheers
<%@ Language = "JavaScript" %>
<html>
<head>
<!-- #include file="../include/ado.inc" -->
<!-- #include file="../include/filters.a
<meta http-equiv="Content-Langua
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>StoreConnect Search</title>
<link href="ExecutionStyles.css"
<style type="text/css">
<!--
.flat {BORDER-RIGHT: #003399 1px solid; BORDER-TOP: #003399 1px solid; BORDER-LEFT: #003399 1px solid; BORDER-BOTTOM: #003399 1px solid; text-decoration: none}
.flatbutton {BORDER-RIGHT: #666666 1px solid; BORDER-TOP: #666666 1px solid; BORDER-LEFT: #666666 1px solid; BORDER-BOTTOM: #666666 1px solid}
.topl {BORDER-TOP: gray 1px solid}
.botl {BORDER-BOTTOM: gray 1px solid;font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #000000; text-align: left;}
.botsl {BORDER-BOTTOM: silver 1px solid;font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #000000; text-align: left;}
.norm {font-family: Verdana,Arial, Helvetica, sans-serif; font-size: 15px; color: #000000; text-align: left;}
.smtxt {font-family: Verdana,Arial, Helvetica, sans-serif; font-size: 13px; line-height: 15px; color: #000000; text-align: left;}
.vsmtxt {font-family: Verdana,Arial, Helvetica, sans-serif; font-size: 10px; line-height: 15px; color: #000000; text-align: left; text-decoration: none}
.hline {font-family: Verdana,Arial, Helvetica, sans-serif; font-size: 12px; color: #000000; text-align: left;}
//-->
</style>
<script language="JavaScript" type="text/javascript">
<!--
function stripHTML( oldString )
{
var newString = "";
var inTag = false;
for( var i = 0; i < oldString.length; i++ )
{
if( oldString.charAt(i) == '<' ) inTag = true;
if( oldString.charAt(i) == '>' ) {
inTag = false;
i++;
}
if( !inTag ) newString += oldString.charAt(i);
}
return newString;
}
//-->
</script>
</head>
<body TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0"">
<%
var Move;
var PageNo;
var TheEnd;
Move = Request("Move");
PageNo = Request("PageNo");
if (!(PageNo > 0 || PageNo < 999)) {
PageNo = 1;
TheEnd = 0;
}
var Q;
Q = Server.CreateObject("ADODB
strSQL = "select Retailer, Brand, ConnectCode, Min(RetailerLogo) as RTlogo, Min(AdHeader) as AdHead, Min(AdImage) as AdImg, Min(MajorChainLogo) as MCLogo, Min(MCName) as MCN from ADRetailersV "
strSQL += " where mcid = '"+Request("ID")+"'";
strSQL += " group by Retailer, Brand, ConnectCode";
strSQL += " order by Retailer";
Q.Open(strSQL, Conn, adOpenStatic);
Q.PageSize = 2;
if (!Q.EOF) {
if (Move == "Previous") {
if (PageNo > 1) {
PageNo--;
} else {
PageNo = 1;
}
}
else if (Move == "Next") {
if (Q.AbsolutePage < Q.PageCount) {
PageNo++;
} else {
PageNo = Q.PageCount;
}
}
else {
PageNo = 1;
}
Q.AbsolutePage = PageNo;
} else
{
TheEnd = 1;
}
%>
<!--Promos table-->
<table width="770" cellspacing=0 cellpadding=0 border=1 class="norm" valign="center">
<%
var Count = 0;
for (var i = 0; i < Q.PageSize; i++) {
if (TheEnd)
{
Response.Write("<div class='hline' align='center'>");
Response.Write("<tr height='100' align='center'><td colspan='6'>Sorry, there are no Major Chains matching your request</td></tr><tr height='150'><td> </td
break;
}
if (Q.EOF) {
break;
}
r1 = Q("AdHead");
r2 = stripHTML(r1);
Response.Write("<td>"+r2+"
Response.Write("<td width='120'> </td></t
Response.Write("<tr>");
Response.Write("</tr>");
if (Count > 1)
Count = 0;
else
Count++;
Q.MoveNext;
}
%>
</table>
<!--Next/Prev Page-->
<table width="765" cellspacing="0" cellpadding="0" border="0" class="smtxt">
<tr>
<td width="600" align="right"> </td>
<td width="130" align="right" class="flat">
<%
if (PageNo > 1) {
Response.Write("<a STYLE='text-decoration:non
}
%>
</td>
<td width="4"> </td>
<%
var i=0;
while((i<Q.PageCount)&&(i<
{
Response.Write("<td><a STYLE='text-decoration:non
i+=1;
}
%>
<td width="4"> </td>
<%
if (PageNo < Q.PageCount) {
Response.Write("<td width='110' align='right' class='flat'><a STYLE='text-decoration:non
}
%>
</tr>
</table>
</body>
</html>
<%
Q.close();
Conn.close();
Conn = null;
%>
Like this. As I said, you're trying to call a server-side function in your asp, you had declared the function as a client-side function.
<body TOPMARGIN="0" LEFTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0"">
<%
function stripHTML( oldString )
{
var newString = "";
var inTag = false;
for( var i = 0; i < oldString.length; i++ )
{
if( oldString.charAt(i) == '<' ) inTag = true;
if( oldString.charAt(i) == '>' ) {
inTag = false;
i++;
}
if( !inTag ) newString += oldString.charAt(i);
}
return newString;
}
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: woodpd {http:#8305056}
Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jAy
EE Cleanup Volunteer
Business Accounts
Answer for Membership
by: MatrixDudPosted on 2003-04-09 at 18:19:09ID: 8303974
this function should do the trick:
function stripHTML( oldString )
{
var newString = "";
var inTag = false;
for( var i = 0; i < oldString.length; i++ )
{
if( oldString[i] == '<' ) inTag = true;
if( oldString[i] == '>' ) inTag = false;
if( !inTag ) newString += oldString[i];
}
return newString;
}