2

I am just putting some html in a var and I get this error: Uncaught SyntaxError: Unexpected token ILLEGAL

typeForm = "Type de RDV : <br />                                                                                                                                                                                   
            <input type='radio' name='rdv-type' value='0' class='rdv-type' />Client seul<br />                                                                                                                     
            <input type='radio' name='rdv-type' value='1' class='rdv-type' />Client + con<br />                                                                                                           
            <input type='radio' name='rdv-type' value='2' class='rdv-type' />Visite agence<br />                                                                                                                   
            <input type='radio' name='rdv-type' value='4' class='rdv-type' />Signature PV<br />                                                                                                                    
            <input type='radio' name='rdv-type' value='5' class='rdv-type' />Con step<br />                                                                                                           
            <input type='radio' name='rdv-type' value='3' class='rdv-type' />Land analysis<br />";

I don't get what I am doing wrong. I get a warning around first <br />.

I checked other posts but I really dont see why it does this.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Jp1987
  • 45
  • 1
  • 8
  • Have you tried removing parts of the string to identify which part is causing the error? – AGB Oct 24 '12 at 08:59
  • 1
    possible duplicate of [How do I break a string across more than one line of code in JavaScript?](http://stackoverflow.com/questions/508269/how-do-i-break-a-string-across-more-than-one-line-of-code-in-javascript) – Quentin Oct 24 '12 at 08:59
  • @Quentin If you don't know that it's a problem with the broken string and only have the error-message you will never be able to get to that question. – Christoph Oct 24 '12 at 09:31

4 Answers4

7

It happens because in JavaScript you can't simply start the new line in a string value, you should either 'escape the new line':

var smth = "Some text \
            continues here \
            and here";

or use string concatenation:

var smth = "Some text " +
           "continues here " +
           "and here";
VisioN
  • 143,310
  • 32
  • 282
  • 281
  • Ah thanks a lot. I had no idea about that. I am kina new to jQuery/js and you sir have taught me something I could have never figured out alone. – Jp1987 Oct 24 '12 at 09:26
1
typeForm = "Type de RDV : <br/>" +                                                                                                                                                                                   
        "<input type='radio' name='rdv-type' value='0' class='rdv-type' />Client seul<br />" +                   
....

and so on

ChuckE
  • 5,610
  • 4
  • 31
  • 59
1

When line breaking append a "+" before each new line

1

Your html string is not correctly formed, Concatenate all line to make a string comprising many lines.

Live Demo

typeForm = "Type de RDV : <br /> " +                                                                                                                                                                                  
           " <input type='radio' name='rdv-type' value='0' class='rdv-type' />Client seul<br />      " +                                                                                                               
           " <input type='radio' name='rdv-type' value='1' class='rdv-type' />Client + con<br />      " +                                                                                                     
          "  <input type='radio' name='rdv-type' value='2' class='rdv-type' />Visite agence<br />       " +                                                                                                            
           " <input type='radio' name='rdv-type' value='4' class='rdv-type' />Signature PV<br />         " +                                                                                                           
            "<input type='radio' name='rdv-type' value='5' class='rdv-type' />Con step<br />           " +                                                                                                
    " <input type='radio' name='rdv-type' value='3' class='rdv-type' />Land analysis<br />";

    alert(typeForm );
Adil
  • 146,340
  • 25
  • 209
  • 204