By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,463 Members | 3,115 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,463 IT Pros & Developers. It's quick & easy.

Unterminated string -- within a querystring...?

P: n/a
Hi, this is the first lines of a function. Although it runs, it still
throws an "Unterminated string constant" error in the browser. It is
all in one line, just wouldn't fit here.

The error appears to occur right after type='+typeIn+'&id <----before
the =

Any clues appreciated! Thanks, Kathy
function Anomaly(typeIn,idIn,textIn)
{
newWindow = window.open(('Anomaly.aspx?type='+typeIn+'&id='+id In+'&text='+textIn),
'Anomaly', 'width=650,height=700,left=100,toolbar=no,menubar= no,resizable=yes');
Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 8 Oct 2003 21:32:48 -0700, in comp.lang.javascript
Ka**********@attbi.com (KathyB) wrote:
| Hi, this is the first lines of a function. Although it runs, it still
| throws an "Unterminated string constant" error in the browser. It is
| all in one line, just wouldn't fit here.
|
| The error appears to occur right after type='+typeIn+'&id <----before
| the =
|
| Any clues appreciated! Thanks, Kathy
|
|
| function Anomaly(typeIn,idIn,textIn)
| {
| newWindow = window.open(('Anomaly.aspx?type='+typeIn+'&id='+id In+'&text='+textIn),
| 'Anomaly', 'width=650,height=700,left=100,toolbar=no,menubar= no,resizable=yes');


You might try breaking the code up-
--------------
function Anomaly(typeIn,idIn,textIn)
{
var URL = "type=" + typeIn + "&id=" + idIn + "&text=" + textIn;

alert ( URL );

newWindow = window.open("Anomaly.aspx?" + URL, "Anomaly",
"width=650,height=700,left=100,toolbar=no,menubar= no,resizable=yes");
}
---------------
Your inputs may have apostrophes which will upset the scheme of
things.
---------------------------------------------------------------
jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------
Jul 20 '05 #2

P: n/a
Thanks. Question, my input will sometimes definitely have apostrophes!
How do I handle that?

Thanks.

Kathy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

P: n/a
Kathy Burke <ka**********@attbi.com> writes:
Question, my input will sometimes definitely have apostrophes! How
do I handle that?


It shouldn't make a difference.

This is perfectly legal:

var x = 'foo\'bar';
var y = "baz'foo";
var z = 'abc'+x+y+'def';

The value of z is the string containing
abcfoo'barbaz'foodef

Your code looked perfectly legal to me, if used in an HTML setting or
an external Javascript file. If you embed it in XHTML, you must turn
the ampersands into &amp; entities.

My guess would be that you inadvertedly inserted a newline without
noticing. That would give the error message that you got.
Otherwise, I would need to see the function in context in order to
say what is wrong. The code you posted is fine in itself.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

P: n/a
Lasse, thanks again for your help. I've including my html output in
hopes that you may see something I don't. I also included an apostrophe
in one of my text items...that, too, gives me an error that jscript is
expecing and } or something. I'm using strictly IE 5.5/6. If you could
look at this, I would be ever so grateful! Thanks.

Kathy

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">
<style type="text/css">
bgcolor="#FFFFFF"
h1 {font-family: Gill Sans MT;color: blue;font-size:20pt
font-weight:bold;margin-top:0;margin-bottom:0}
h2 {font-family: Gill Sans MT;color: red;font-size:18pt
font-weight:bold;margin-top:0;margin-bottom:0}
h3 {font-family: Gill Sans MT;color:
white;font-size:14pt;font-weight:bold;margin-top:0;margin-bottom:0}
body {font-family: Gill Sans MT;color: black;font-size:12pt}
p {font-family: Gill Sans MT;color: black;font-size:12pt}
h4 {font-family: Gill Sans MT;color:
white;font-size:12pt;font-weight:bold;text-transform:
uppercase;margin-top:0;margin-bottom:0}
h5 {font-family: Gill Sans MT;color:
white;font-size:12pt;font-weight:bold;margin-top:0;margin-bottom:0}
h6 {font-family: Gill Sans MT;color:
black;font-size:12pt;font-weight:bold;margin-top:0;margin-bottom:0}
</style>
<title>Work Instruction</title><script language="Javascript">
function Anomaly(typeIn,idIn,textIn)
{
newWindow = window.open(('Anomaly.aspx?type=' + typeIn + '&idNo=' +
idIn + '&text=' + textIn), 'Anomaly',
'width=650,height=700,left=100,toolbar=no,menubar= no,resizable=yes');
}
function ValidateSave(formRef,fieldName,min,max) {
var formField = formRef.elements[fieldName];
if (!/^\d+(\.\d+)?$/.test(formField.value)) {
alert('Invalid entry...please try again!');
formField.focus();
formField.select();
return false;
}
if ((formField.value < min) || (formField.value > max)) {
alert("The entry must be between " +min+ " and " +max+ ".");
formField.focus();
formField.select();
return false;
}
else
{
varScroll = document.body.scrollTop;
document.cookie="position="+varScroll;
return confirm("You are about to enter: " +formField.value+ " --
click OK to proceed.");
}
}
function ConfirmSave(formRef,fieldName)
{
var formField = formRef.elements[fieldName];

if ((formField.value.length==0) || (formField.value==null))
{
alert("You are trying to save a blank entry.");
formField.focus();
formField.select();
return false;
}
else {
varScroll = document.body.scrollTop;
document.cookie="position="+varScroll;
return confirm("You are about to enter: " +formField.value+ " --
click OK to proceed.");
}
}
function CheckInput()
{
var cnAll = document.all;
for (var i=0;i<cnAll.length;i++)

if(cnAll(i).type=='text')
{
alert("You must first complete and SAVE all user inputs!");
cnAll(i).focus();
return false;
}
document.cookie="position=0";
return true;
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
// if cookie exists
if (offset != -1) {
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(off set, end))
}
}
return returnvalue;
}
function myScroll()
{
if (get_cookie("position")!="") {
varScroll = "";
varScroll = get_cookie("position");
window.scrollTo(0, varScroll);
}
}
</script></head>
<body onload="myScroll()">
<h1></h1>
<table border="1" width="100%" cellpadding="4">
<tr bgcolor="red" valign="middle">
<th colspan="3" align="left">
<h3>SAFETY</h3>
</th>
</tr>
<tr>
<td align="center" valign="middle" width="5%"><input style="CURSOR:
POINTER" type="button" value="Anomaly"
onclick="javascript:Anomaly('Safety','1','Static prevention straps and
lab coats must be worn at all
times.')"></td>
<td valign="top">
<table border="0">
<tr>
<td align="left" valign="top">1. *
</td>
<td valign="top">
<p>Static prevention straps and lab coats must be worn at all
times.</p>
</td>
</tr>
</table>
</td>
</tr>
</table><br><table border="1" width="100%" cellpadding="4">
<tr bgcolor="orange" valign="middle">
<th colspan="3" align="left">
<h3>TOOLS AND MATERIALS</h3>
</th>
</tr>
<tr>
<td colspan="2"><b>Tool/Material</b></td>
<td align="center"><b>Jabil Part No.</b></td>
</tr>
</table><br><table border="1" width="100%" cellpadding="4">
<tr bgcolor="navy" valign="middle">
<th align="left" colspan="4">
<h3>PROCESS STEPS</h3>
</th>
<tr onMouseOver="this.bgColor = '#99FFFF'" onMouseOut="this.bgColor =
'#FFFFFF'">
<td align="center" valign="middle"><input style="CURSOR: POINTER"
type="button" value="Anomaly"
onclick="javascript:Anomaly('Step','1','Scan all labels from the sheet
before installing on the boards. The total quantity scanned should equal
the total quantity of the work order.')"></td>
<td valign="top">
<table width="100%" border="0" cellpadding="0">
<tr>
<td valign="top" width="7">
<table border="0" cellpadding="0">
<tr>
<td valign="top" width="7">**</td>
<td valign="top">1.**</td>
</tr>
</table>
</td>
<td>
<p>Scan all labels from the sheet before installing on the boards. The
total quantity scanned should equal the total quantity of the work
order.</p>
</td>
</tr>
</table>
</td>
</tr>
<tr onMouseOver="this.bgColor = '#99FFFF'" onMouseOut="this.bgColor =
'#FFFFFF'">
<td align="center" valign="middle"><input style="CURSOR: POINTER"
type="button" value="Anomaly"
onclick="javascript:Anomaly('Step','2','Install P/N label and S/N label
as shown in visual aid TEST 10-ME40-865-7446-03-LB01
10-ME40-865-7446-03-LB01.')"></td>
<td valign="top">
<table width="100%" border="0" cellpadding="0">
<tr>
<td valign="top" width="7">
<table border="0" cellpadding="0">
<tr>
<td valign="top" width="7">**</td>
<td valign="top">2.**</td>
</tr>
</table>
</td>
<td>
<p>Install P/N label and S/N label as shown in visual aid TEST <a
target="_blank"
href="\\BOSCIM01\CIMBridge\!PROCESS_ENGINEERING\LT X\865-333-03-RAC\LB01.
mdf">10-ME40-865-7446-03-LB01</a><a target="_blank"
href="\\BOSCIM01\CIMBridge\!PROCESS_ENGINEERING\LT X\865-7446-03RBC\LB01.
mdf">10-ME40-865-7446-03-LB01</a>.</p>
</td>
</tr>
</table>
</td>
</tr>
<tr onMouseOver="this.bgColor = '#99FFFF'" onMouseOut="this.bgColor =
'#FFFFFF'">
<td align="center" valign="middle"><input style="CURSOR: POINTER"
type="button" value="Anomaly"
onclick="javascript:Anomaly('Step','3','Kathy's Test -- Load the boards
into the loader or into the EKRA E5 Screen Printer manually, as
required.')"></td>
<td valign="top">
<table width="100%" border="0" cellpadding="0">
<tr>
<td valign="top" width="7">
<table border="0" cellpadding="0">
<tr>
<td valign="top" width="7">**</td>
<td valign="top">3.**</td>
</tr>
</table>
</td>
<td>
<p>Kathy's Test -- Load the boards into the loader or into the EKRA E5
Screen Printer manually, as required.</p>
</td>
</tr>
</table>
</td>
</tr>
<tr onMouseOver="this.bgColor = '#99FFFF'" onMouseOut="this.bgColor =
'#FFFFFF'">
<td align="center" valign="middle"><input style="CURSOR: POINTER"
type="button" value="Anomaly"
onclick="javascript:Anomaly('Step','4','Operate the EKRA E5 Screen
Printer, see LINK if needed.')"></td>
<td valign="top">
<table width="100%" border="0" cellpadding="0">
<tr>
<td valign="top" width="7">
<table border="0" cellpadding="0">
<tr>
<td valign="top" width="7">**</td>
<td valign="top">4.**</td>
</tr>
</table>
</td>
<td>
<p>Operate the EKRA E5 Screen Printer, see LINK if needed.</p>
</td>
</tr>
</table>
</td>
</tr>
</tr>
<form name="finish" action="HiddenFinish.aspx?finish=yes" method="post"
onsubmit="return CheckInput(this);">
<tr bgcolor="red" valign="middle">
<td align="center" valign="middle"><input style="CURSOR: POINTER"
type="submit" name="finish" value="FINISH"></td>
<td align="left">
<font color="white"><b>Click the FINISH button when work instruction is
complete.</b></font>
</td>
</tr>
</form>
</table>
</body>
</html>
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5

P: n/a
Kathy Burke <ka**********@attbi.com> writes:
I've including my html output in hopes that you may see something I
don't. I also included an apostrophe in one of my text items...that,
too, gives me an error that jscript is expecing and } or something.
I'm using strictly IE 5.5/6. If you could look at this, I would be
ever so grateful!
Ok, I threw this at IE 6. The error report says unterminated string
constant on line 46. That is this line:
return confirm("You are about to enter: " +formField.value+ " --
click OK to proceed.");


Or, more accuratly, these *two* lines.

Maybe your news client have broken the line (which is why you
shouldn't post code with lines longer than about 72 characters, some
newsreaders, including yours, will mangle the code by breaking
lines.).

IE goes on to warn about unterminated string constants on lines:
63, 117, 149, 173, and 221

It also says: Expected ")" on line 198.

Then it starts running and gets "Object expected" on line 107.

I fixed the unterminated string constants by removing the newlines.

The Expected ")" error ended up at line 195, which, sadly, makes no
sense. Line 195 is "</tr>".

Ah. The bug is a few lines further down, at:

onclick="javascript:Anomaly('Step','3','Kathy's Test -- Load the boards into the loader or into the EKRA E5 Screen Printer manually, as required.')"></td>

The ' in Kathy's ends the string, and must be escaped:

onclick="javascript:Anomaly('Step','3','Kathy\'s Test -- Load the boards into the loader or into the EKRA E5 Screen Printer manually, as required.')"></td>

There is no problem having 's in string literals, but you must either
escape them or quote the string literals with "'s instead. In this
case, those would also need to be quoted, since the attribute is
wrapped in double quotes.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.