469,312 Members | 2,524 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

problem with a string

Hi all...

I got this script where I have to declare a string thats as wide as a whole
webpage. The problem is that it takes several lines to finish the whole
string and, when I try to load it, I get an error saying that there was a
caracter expected at the end of the line... Does anybody know how can I make
notice that my variable is several lines wide?
<html>
<head>
<title>Dovip 845 Navigator</title>
<meta http-equiv=\"Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="refresh" content="50">
<script type="text/javascript">
function contrasenya()
{
var elhtm="<table width=\"90%\" align=\"center\" cellpadding=\"0\"
cellspacing=\"0\"><tr><td width=\"27%\"><strong><font size=\"5\"
face=\"Courier New, Courier, mono\" color=\"#009900\">Safe</font><font
size=\"5\" face=\"Courier New, Courier, mono\"
color=\"#CC0033\">Line,S.L.</font></strong></td><td
width=\"7%\">&nbsp;</td><td width=\"56%\"><strong><font color=\"#009966\"
face=\"Courier New, Courier, mono\">Estado del equipo :</font><font
color=\"#CC0000\">¿%$P ¿%$Q \"><font
color=\"#00FF00\">&nbsp; ¿%$p </font></td><td bgcolor=\"#000000\"><font
color=\"#CCCCCC\">0.3mS - 5mS</font></td><td bgcolor=\"#000000\"><font
color=\"#00FF00\">&nbsp; ¿%$x ¿%$q </font></td></tr></table>\";
var a=prompt("escribe la contraseña");
if (a=="safeline") endavant(elhtm);
else barrera();
}
function endavant(elhtm)
{
document.getElementById("writeArea").innerHTML=elh tm
function barrera()
{
document.getElementById("writeArea").innerHTML="Co ntraseña incorrecta!!!!
Refresca la pagina y escribe la contraseña correcta."; }
</script>
</head>
<body onLoad="contrasenya()" bgcolor="#FF9900" text="#000000"nk="#0000CC">
<div id="writeArea"></div>
</body>
</html>


/* if reduced elhtm so it's not so big, but you'd have to see it as a var
that gets to the end of the line and keeps on, thus making my browser as for
the end of the var (";" at the end of the line, instead of keeping on
reading....

Any idea?

Yodai */
Jul 20 '05 #1
1 1205
On Wed, 14 Jan 2004 18:20:41 GMT, Yodai <yo***@spamnot.mail.vu> wrote:
<title>Dovip 845 Navigator</title>
<meta http-equiv=\"Content-Type" content="text/html; charset=iso-8859-1"> ^
I don't think that, the backslash, should be there.
<meta http-equiv="refresh" content="50">
<script type="text/javascript">
function contrasenya()
{
var elhtm="<table width=\"90%\" align=\"center\" cellpadding=\"0\"
cellspacing=\"0\"><tr><td width=\"27%\"><strong><font size=\"5\"
face=\"Courier New, Courier, mono\" color=\"#009900\">Safe</font><font
size=\"5\" face=\"Courier New, Courier, mono\"
color=\"#CC0033\">Line,S.L.</font></strong></td><td
width=\"7%\">&nbsp;</td><td width=\"56%\"><strong><font color=\"#009966\"
face=\"Courier New, Courier, mono\">Estado del equipo :</font><font
color=\"#CC0000\">¿%$P ¿%$Q \"><font
color=\"#00FF00\">&nbsp; ¿%$p </font></td><td
bgcolor=\"#000000\"><font
color=\"#CCCCCC\">0.3mS - 5mS</font></td><td bgcolor=\"#000000\"><font
color=\"#00FF00\">&nbsp; ¿%$x ¿%$q </font></td></tr></table>\";
If you notice, you escape the final double-quote mark. As far as the
JavaScript parser is concerned, you haven't terminated the string.

Rather than escaping all of the quotes, make life easier for your self;
use single-quotes (') for JavaScript strings and double-quotes inside
them. Also, instead of one huge string, break it up into several
concatenated strings. Lastly, though you escaped the nested double-quotes,
you didn't escape the forward slashes[1]. Some browsers (certainly used
to) interpret the sequence, </ as the end of script and style blocks, even
if in full the sequence was </TABLE>, for example. Instead make sure you
do <\/. All of these recommendations result in this:

var elhtm = '<table width="90%" align="center" cellpadding="0"'
+ ' cellspacing="0"><tr><td width="27%"><strong><font size="5"'
+ ' face="Courier New, Courier, mono" color="#CC0033">Line,S.L.'
+ '<\/font><\/strong><\/td><td width="7%">&nbsp;<\/td><td'
+ ' width="56%"><strong><font color="#009966" face="Courier New,'
+ ' Courier, mono">Estado del equipo :<\/font><font'
+ ' color="#CC0000">¿%$P ¿%$Q "><font'
+ ' color="#00FF00">&nbsp; ¿%$p <\/font><\/td><td'
+ ' bgcolor="#000000"><font color="#CCCCCC">0.3mS - 5mS<\/font>'
+ '<\/td><td bgcolor="#000000"><font color="#00FF00">&nbsp;'
+ ' ¿%$x ¿%$q <\/font><\/td><\/tr><\/table>';

<snip>
function endavant(elhtm)
{
document.getElementById("writeArea").innerHTML=elh tm


You're missing the terminating semi-colon (;) and closing brace (}).

<snip>

Mike
[1] I don't know if this is still an issue, but as I was recently reminded
of it whilst reading the HTML specification, I thought I'd mention it.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by muser | last post: by
18 posts views Thread by Ian Stanley | last post: by
7 posts views Thread by Ankit Aneja | last post: by
4 posts views Thread by David Scemama | last post: by
8 posts views Thread by Rinaldo | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.