Link to home
Start Free TrialLog in
Avatar of lshane
lshane

asked on

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

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
Javascript uses "\n" for line breaks -- try that.

Thanks!
Phil
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
Avatar of lshane
lshane

ASKER

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
@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
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
Avatar of lshane

ASKER

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
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.
Avatar of lshane

ASKER

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.
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.
ASKER CERTIFIED SOLUTION
Avatar of peterxlane
peterxlane

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
Avatar of lshane

ASKER

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
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?
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
@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.

Avatar of lshane

ASKER

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
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.

Avatar of lshane

ASKER

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.