How to make one long line of code on multiple lines?

Discussion in 'JavaScript' started by lost, Oct 20, 2005.

  1. #1
    I have a really long line of code and i was wondering what the syntax is so that i could have it on multiple lines, for easier readibility.
     
    lost, Oct 20, 2005 IP
  2. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #2
    Not for stuffing into a XSS then? ;)
     
    mcfox, Oct 20, 2005 IP
  3. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Sorry, I have no idea what XSS is?
    I just want to break up the long lines of code so that they are more readible.
     
    lost, Oct 20, 2005 IP
  4. Skeleton

    Skeleton Peon

    Messages:
    116
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you can break into a new line whenever a space you have encountered. For example:

    if (a == b) {
    alert('Hello World');
    }

    is equal to

    if
    ( a == b
    ) {
    alert
    ('Hello World')
    ;
    }

    The reason is that the most of the languages ignores the whitespace file compiling the code.
     
    Skeleton, Oct 20, 2005 IP
  5. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It doesnt seem to work...
     
    lost, Oct 20, 2005 IP
  6. Skeleton

    Skeleton Peon

    Messages:
    116
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Would you like to send that exact line of code ?
     
    Skeleton, Oct 20, 2005 IP
  7. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    document.getElementById("textfields").innerHTML += '<B><FONT SIZE=2>Item '+numItems+'  </B>Barcode  <INPUT TYPE="text" NAME="textfield2" VALUE="" > <A HREF="cca-assembly.php"><IMG SRC="C:/Server/Apache2/htdocs/Images/down_arrow.gif" HEIGHT=19 WIDTH=20 ALIGN=TOP></A><BR></B>Description <INPUT TYPE="text" NAME="textfield2" VALUE=""> Part Number <INPUT TYPE="text" NAME="pnotextfield" VALUE=""> Serial Number <INPUT TYPE="text" NAME="serialnofield" VALUE"" ONKEYDOWN="if (event.keyCode==9) { addNewItem(); }"><A HREF="cca-assembly.php"><IMG SRC="C:/Server/Apache2/htdocs/Images/down_arrow.gif" HEIGHT=19 WIDTH=20 ALIGN=TOP> </A><BR>';
    Code (markup):
     
    lost, Oct 20, 2005 IP
  8. Skeleton

    Skeleton Peon

    Messages:
    116
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Try this (or sth like this format):

    
    document.getElementById("textfields").innerHTML += '<B><FONT SIZE=2>Item ' + 
    	numItems + '  </B>Barcode  <INPUT TYPE="text" NAME="textfield2" VALUE="" >' +
    	' <A HREF="cca-assembly.php"><IMG SRC="C:/Server/Apache2/htdocs/Images/down_arrow.gif"' +
    	' HEIGHT=19 WIDTH=20 ALIGN=TOP></A><BR></B>Description <INPUT TYPE="text" NAME=' +
    	'"textfield2" VALUE=""> Part Number <INPUT TYPE="text" NAME="pnotextfield" VALUE=""> ' +
    	'Serial Number <INPUT TYPE="text" NAME="serialnofield" VALUE"" ONKEYDOWN="if ' +
    	'(event.keyCode==9) { addNewItem(); }"><A HREF="cca-assembly.php"><IMG ' +
    	'SRC="C:/Server/Apache2/htdocs/Images/down_arrow.gif" HEIGHT=19 WIDTH=20 ALIGN=TOP> </A><BR>';
    
    Code (markup):
     
    Skeleton, Oct 20, 2005 IP
  9. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thank you, that worked!
     
    lost, Oct 20, 2005 IP