Web Analytics Made Easy -
StatCounter Multiline - CodingForum

Announcement

Collapse
No announcement yet.

Multiline

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiline

    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.

  • #2
    you just need to use the Enter key:

    if (condition1 &&
    condition2 ||
    condition3)
    {

    }
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      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.

      Comment


      • #4
        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

        Comment


        • #5
          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.
          Glenn
          vBulletin Mods That Rock!

          Comment


          • #6
            Breaking up lines

            Thanks pastor and glenn.

            Both of those methods work nicely.

            Comment

            Working...
            X