• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3961
  • Last Modified:

Getting message: Microsoft JScript runtime error '800a1391' 'vbCrLf' is undefined

Hi.  I'm using Classic ASP JS.  I'm trying to figure out the code to use for the "line break" in JS.  I used the string from one of my VBScript pages, but I get the error posted in the "Title" box above.

Here's the line:

<p><%=Replace(rsProdDetail.Fields.Item("ProdLongDesc").Value, vbCrLf, "<br>")%></p>


I've tried replacing the "vbCrLf" with "\n", but still get a similar error.

Could someone, please, help me with a JS-equivalent for this?


Thanks,
Shane
0
lshane
Asked:
lshane
  • 6
  • 4
  • 4
  • +2
1 Solution
 
b0lsc0ttCommented:
lshane,

Did you try \n with quotes or without?  Did you get the same error message as in the question's title when you changed VbCrLf to \n or "\n"?

b0lsc0tt
0
 
peh803Commented:
Javascript uses "\n" for line breaks -- try that.

Thanks!
Phil
0
 
peh803Commented:
b0lsc0tt : sorry, obviously based on the identical timestamps of your post and mine, I didn't see yours before making my post!  No "point stealing" intended here...

Regards,
Phil / peh803
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
lshaneAuthor Commented:
Thanks for your speedy reply, b0lsc0tt.  I tried it both ways, actually.

Without quotes I get:
-----------------------------------------------------------------------------------------------------------------
Microsoft JScript compilation error '800a03f6'

Invalid character

/product_details.asp, line 196

Response.Write(Replace(rsProdDetail.Fields.Item("ProdLongDesc").Value, \n, "<br>"))
-----------------------------------------------------------------------------------------------------------------



With quotes I get:
-----------------------------------------------------------------------------------------------------------------

Microsoft JScript runtime error '800a138f'

Object expected

/product_details.asp, line 196

-----------------------------------------------------------------------------------------------------------------

"Line 196" is the code line:  
<p><%=Replace(rsProdDetail.Fields.Item("ProdLongDesc").Value, "\n", "<br>")%></p>


Your help is greatly appreciated,
Shane
0
 
b0lsc0ttCommented:
@peh803 - No problem.  Has happened plenty of times to me too and I'm glad that you posted to confirm \n for JavaScript.  It is not my expertise.  If our comments solve the problem then splitting is what I would do and I have no objection if that happens.

bol
0
 
peh803Commented:
try it this way instead:
   <p><%=Replace(rsProdDetail.Fields("ProdLongDesc").Value, "\n", "<br>")%></p>

Also, make sure your recordset object reference variable is spelled correctly.

It should be correct to use quotes, as above.

Regards,
Phil
0
 
lshaneAuthor Commented:
That's the way I tried a moment ago, and it rendered the following error message:

-----------------------------------------------------------------------------------------------------------------
Microsoft JScript runtime error '800a138f'

Object expected

/product_details.asp, line 196
-----------------------------------------------------------------------------------------------------------------

I know the spelling is correct, because if I remove all the "replace" jargon, it displays fine... it's just all "bunched up".  No carriage returns are being detected.  This very line (while using "vfCrLf") in my ASP VBScript page works fine.

Am I missing something in the syntax for JS?  I'm stumped.

Thanks,
Shane
0
 
b0lsc0ttCommented:
lshane,

Phil's line looked a little different than the one you used.  He suggested that you leave out .Item from the line.  That may not make a difference though and may have been unintentional.

Try replacing a different character to see if the problem is the \n or something else with the Replace statement.
0
 
lshaneAuthor Commented:
Hi, b0lsc0tt.  I actually just copied-and-pasted his line in my code.  Same error.


I really appreciate your efforts.  It just seems to me that there is always a parallel between VBScript and JS when using ASP, but this one seems to be difficult.
0
 
b0lsc0ttCommented:
In most cases you are correct but the replace in JScript may not be Replace.  Also JScript is probably case sensitive while VBScript is not.  The only equivalent that I have been able to find for VBScripts Replace is strObj.replace(rgExp, textToReplace).  Did you try my test?  Are you sure that Replace works in JScript?

If you aren't sure and want to try the replace method I used you could try something like ...

<%@ Language = JScript %>
var Description = rsProdDetail.Fields.Item("ProdLongDesc").Value;
Description = Description.replace("\n", "<br>");
%>

Notice that replace is lower case and the lines end with a semicolon.  You may already have those but just wanted to point them out.  If this doesn't work then maybe Phil has more experience with JScript or another expert.  It will help if we determine if the problem is replace or using \n.
0
 
peterxlaneCommented:
The replace function in JavaScript works differently than in VBScript.  It looks like this:

<%
var mystring = "hello world";
Response.Write(mystring.replace("h", "H"));
%>

And as I understand it, it uses a regular expression to do the replace, so you should be able to do the following:

<%
strJSCarriageReturn = /\n/g;
strDBField = rsProdDetail.Fields("ProdLongDesc").Value;
Response.Write(strDBField.replace(strJSCarriageReturn, "<br />"));
%>

Javascript is also case sensitive so it must be lower case.  The regular expression gets enclosed in "/" and then the "g" at the end indicates that it is a global search and replace, not just the first occurrence...







0
 
lshaneAuthor Commented:
Peterxlane - yours worked great.  Thank you.  Now that we have that resolved, I have one other question for you.

How can I "save" formatted text?  In other words, on the "Insert Item" form, in the "Administration" area, I enter the text, along with carriage returns, etc., and those display excellently now (thanks to your code); however, in that text, there are headings which I would like to bold.  How can I bold them in the "Insert Item" textarea, and have them displayed as bolded on the "Details" page on the live site?  Is there a relatively, feasible way to accomplish that?

Thanks so much,
Shane
0
 
peterxlaneCommented:
if the text has html in it and that is stored in the database, then it should retain that formatting when it is displayed on the page...

<b>hello world</b>

would show up bold

<h1>hello world</h1>

would show up as a heading


What am I missing?
0
 
houguanCommented:
To show formatted text, you need to user Server.HTMLEncode also

example:
<%
abc="<b>hello</b>"
Response.Write(abc&"<br>")
Response.Write(Server.HTMLEncode(abc))
%>

Output
====
<b>hello</b>
hello  <--in bold
0
 
peterxlaneCommented:
@houguan - That would actually produce the opposite of what you posted.  The first one would be bold and the second one would show the html tags... which means that you would not need to do anything special to get things to display in HTML.

0
 
lshaneAuthor Commented:
Hello, peterxlane and houguan.  Thanks so much for your diligence on this.  I'm still learning.

Actually, I know I could hand-code the HTML in the textarea field, however, I'm just wanting to copy-and-paste from something, such as MS Word... OR, I'd like to just press <CTRL-B> to bold the text, etc.  Is this possible with the "Server.HTMLEncode"?

In other words, if I copy a typed description from MS Word, which includes bolded headers, etc., then I would like that formatting to be maintained when I paste it into the textarea field of the "Insert Item" form.

How can that be accomplished?


Thanks so much,
Shane
0
 
peterxlaneCommented:
You would need some sort of online HTML editor.  Just Google "online HTML editor" and you will find a bunch of different products.  Some are definitely available for free and are pretty easy to implement.

0
 
lshaneAuthor Commented:
Hi, peterxlane.  That's kind of what I thought.  I was just hoping there was a way around it.  Hopefully I can find one that's simple to implement, as you suggested.

Thanks so much for your assistance.
0

Featured Post

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!

  • 6
  • 4
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now