Closed Thread Icon

Topic awaiting preservation: Multine innerhtml (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8333" title="Pages that link to Topic awaiting preservation: Multine innerhtml (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Multine innerhtml <span class="small">(Page 1 of 1)</span>\

 
Lala
Bipolar (III) Inmate

From: Montreal, Canada
Insane since: Feb 2002

posted posted 10-04-2002 23:36

Is there a escape sequence for multiline statements (I'm want to put a couple of tables using document.getElementById(id.innerHTML but i dont want to do it all in the same line


100 lifes
Lala

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 10-04-2002 23:48

Well, you can do this:

document.getElementById(id).innerHTML = "blah blah blah"
+ "blah blah blah"
+ "blah blah blah";

there's no one-statement-per-line restriction. You just can't let the quotes themselves span the newline character.

Lala
Bipolar (III) Inmate

From: Montreal, Canada
Insane since: Feb 2002

posted posted 10-05-2002 00:07

Thanks

100 lines
Lala

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 10-05-2002 21:08

I think I'll take this opportunity to warn those of you who like to ignore semi-colons in your code. This is a rare possibility, but it can happen. Suppose you wrote this code:

a=b+c
(a==d)?func1():func2()

This two line code will likely cause an error. 100 points to anyone who can say why.

[edit: added word "likely"]

[This message has been edited by Slime (edited 10-05-2002).]

kuckus
Bipolar (III) Inmate

From: Berlin (almost)
Insane since: Dec 2001

posted posted 10-05-2002 21:48

I suppose if the browser ignores the line break it might try to multiply c with either true or false, or maybe with one of the function names. Do I win?

kuckus (cell #282)

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 10-05-2002 21:50

Right idea, but not exactly correct; you get partial credit =)

meccaman
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2002

posted posted 10-07-2002 07:40

You don't have paretheses around the conditional statement so the 1st statement gets included as part of the condition.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 10-07-2002 17:06

I think you've basically got it. The problem is, since there are no semicolons, the interpreter (the browser running the javascript) is forced to put them in itself. The rules for automatic semicolon insertion are:

1. if leaving the semicolon out at the end of the line would cause a syntax error, put one in.
2. otherwise, if it's possible to understand the code without inserting a semicolon, don't.

So the interpreter sees the two statements as this:

a=b+c(a==d)?func1():func2()

And it looks for a function named "c". That function probably doesn't exist, so an error is thrown. (Note that it's not a *syntax* error, because the syntax itself makes sense. That's why a semicolon wasn't inserted.)

« BackwardsOnwards »

Show Forum Drop Down Menu