Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Error with ASP

Status
Not open for further replies.

basball321

Programmer
May 18, 2011
4
US
Is there a way to delete a carriage return value that is returned by an ASP command?

I have a very VERY limited ASP server which only supports about 2 functions (Read/Write). Everything works fine for reading integer values, but when I try to read string values into a javascript variable there is a carriage return at the end and it throws an error. Here is my command:

var jsVar1 = '<% ReadPLC("aspVar1");%>';

and this is what what I get when the ASP command returns the String 'teststring':

var jsVar1 = 'teststring
'; <--carriage return???

The error from IE is "Expected ';'"

Any Ideas on how to eliminate the carriage return? I've tried the backspace character, delete character, and about everything in between.

 
Why is there a semicolon inside the ASP delimiters?


which is probably being taken by the javascript engine as an end of statement.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
The semicolon is required by the ASP server. Without the semicolon the ASP reports an error for an invalid function. I think the ASP function replaces that whole phrase before the html file is sent to the client. So javascript wouldn't even see the semicolon right?
 
Ok the interpreter is possibly running JScript then

under normal circumstance it would a simple case of

Code:
var jsVar1 = '<% replace(ReadPLC("aspVar1");%>,vbCrLf,'')';

But if your ASP interpreter only has Read & Write functions for the connected device, it will either have to be handled by the connected device or the developer of the interpreter.

Have you tried a javascript replace immediately after initialising the value?

var jsVar1 = '<% ReadPLC("aspVar1");%>';
jsVar1.replace('/n','');


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Chris, thanks for the quick replies... I have tried the replace method and no luck.

I was mistaken earlier. The error I recieve is "Unterminated String Constant" not "Expected ';'"

The ASP server lives on an Embedded device so there is no way for me to manipulate the ASP interperter... any other client side approaches that might work?
 
So I found a solution using HTML as a buffer...

<body>
<input type="hidden" id="var1" value="<% ReadPLC("aspVar1");%>" />
</body>

<script>
var jsVar1 = document.getElementById('var1').value;
</script>

 
Minor syntax error in
Code:
var jsVar1 = '<% replace(ReadPLC("aspVar1");%>,vbCrLf,'')';
1) It assumes the server is using vbscript
2) The replace is not terminated correctly
If we assume the server is using VBScript, it should be

Code:
var jsVar1 = '<% replace(ReadPLC("aspVar1"),vbCrLf,"") %>';
but since you say that ReadPLC needs to be followed by a ;, it implies that the server is using javascript. In that case it should be
Code:
var jsVar1 = '<% ReadPLC("aspVar1").replace("\n",""); %>';
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top