PDA

View Full Version : Multiline



rah111
Jul 2nd, 2002, 02:14 AM
Hi there.

This is a simple one I think but I couldn't find anything in my HTML or JavaScript reference books.

How do I write JavaScript programming code over more than one line. That is, how do I break it up?

With Visual FoxPro, for example, I would use +; like follows:

COPY FIELDS NAME, AGE, ADDRESS, GROUP, INCOME, +;
OCCUPATION, STATUS TO TEMPORARY_TABLE

How do I do likewise with a long JavaScript line of code?

Thanks.

Russell.

glenngv
Jul 2nd, 2002, 02:56 AM
you just need to use the Enter key:

if (condition1 &&
condition2 ||
condition3)
{

}

rah111
Jul 2nd, 2002, 03:31 AM
Glenn.

Thanks for your email but my code doesn't work using enter.

I have the following code:

<html>
<body>
<script language="javascript">
var boy="Johnny"
var girl="Mary"
document.write("<table><tr><td><b><h2>"+boy+"</h2></b></td></tr><tr><td><b><h3>"+girl+"</h3></b></td></tr></table>" )
</script>
</body>
</html>

Whilst I keep the document.write on one long line in my text editor everything renders ok, but if I break the line by entering at any point then it doesn't work.

I'd like to break the line up so I can see my code more clearly in order to maintain it, but I can't work out how to do that.

Russell.

pastorOfMuppets
Jul 2nd, 2002, 03:40 AM
Try This

<html>
<body>
<script language="javascript">
var boy="Johnny"
var girl="Mary"
var outputText = "<table><tr><td><b><h2>"+"
outputText = outputText + "boy+"</h2></b></td></tr><tr>"
outputText = outputText + "><td><b><h3>"+girl+"</h3></b>"
outputText = outputText + "</td></tr></table>"
document.write(outputText)
</script>
</body>
</html>

I didn't test this, but That is how u create a query in an ASP.

PS I think you would be better to leave the text on one line, just for simplicity sake. What i have done above, introduces 4 lines for those damm bugs to crawl in :) but do as u please

:thumbsup:

glenngv
Jul 2nd, 2002, 03:42 AM
you just can't break at any point as you said.
you only break before or after an operator.
you can't break inside a string literal, if the string literal is too long, you can split it into many separate literals.

you would do it like this:

document.write("<table><tr><td><b><h2>"+
boy+
"</h2></b></td></tr>"+
"<tr><td><b><h3>"+
girl+
"</h3></b></td></tr></table>" )



Originally posted by rah111
Glenn.

Thanks for your email but my code doesn't work using enter.

I have the following code:

<html>
<body>
<script language="javascript">
var boy="Johnny"
var girl="Mary"
document.write("<table><tr><td><b><h2>"+boy+"</h2></b></td></tr><tr><td><b><h3>"+girl+"</h3></b></td></tr></table>" )
</script>
</body>
</html>

Whilst I keep the document.write on one long line in my text editor everything renders ok, but if I break the line by entering at any point then it doesn't work.

I'd like to break the line up so I can see my code more clearly in order to maintain it, but I can't work out how to do that.

Russell.

rah111
Jul 2nd, 2002, 03:47 AM
Thanks pastor and glenn.

Both of those methods work nicely.