problem with a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yodai

    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%\">&n bsp;</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=\"#0000 00\"><font
    color=\"#CCCCCC \">0.3mS - 5mS</font></td><td bgcolor=\"#0000 00\"><font
    color=\"#00FF00 \">&nbsp; ¿%$x ¿%$q </font></td></tr></table>\";
    var a=prompt("escri be la contraseña");
    if (a=="safeline") endavant(elhtm) ;
    else barrera();
    }
    function endavant(elhtm)
    {
    document.getEle mentById("write Area").innerHTM L=elhtm
    function barrera()
    {
    document.getEle mentById("write Area").innerHTM L="Contraseña incorrecta!!!!
    Refresca la pagina y escribe la contraseña correcta."; }
    </script>
    </head>
    <body onLoad="contras enya()" bgcolor="#FF990 0" text="#000000"n k="#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 */


  • Michael Winter

    #2
    Re: problem with a string

    On Wed, 14 Jan 2004 18:20:41 GMT, Yodai <yodai@spamnot. mail.vu> wrote:
    [color=blue]
    > <title>Dovip 845 Navigator</title>
    > <meta http-equiv=\"Content-Type" content="text/html; charset=iso-8859-1">[/color]
    ^
    I don't think that, the backslash, should be there.
    [color=blue]
    > <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%\">&n bsp;</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=\"#0000 00\"><font
    > color=\"#CCCCCC \">0.3mS - 5mS</font></td><td bgcolor=\"#0000 00\"><font
    > color=\"#00FF00 \">&nbsp; ¿%$x ¿%$q </font></td></tr></table>\";[/color]

    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%"><st rong><font size="5"'
    + ' face="Courier New, Courier, mono" color="#CC0033" >Line,S.L.'
    + '<\/font><\/strong><\/td><td width="7%">&nbs p;<\/td><td'
    + ' width="56%"><st rong><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="#00000 0"><font color="#CCCCCC" >0.3mS - 5mS<\/font>'
    + '<\/td><td bgcolor="#00000 0"><font color="#00FF00" >&nbsp;'
    + ' ¿%$x ¿%$q <\/font><\/td><\/tr><\/table>';

    <snip>
    [color=blue]
    > function endavant(elhtm)
    > {
    > document.getEle mentById("write Area").innerHTM L=elhtm[/color]

    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.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    Working...