-5

I was trying to add button using JavaScript, but instead of adding the button to the page, it is throwing an SyntaxError: Invalid or unexpected token

document.write('

<p>Sign in</p>
    <form action="/chat" method="GET">
      <p> Login: <input type="text" name="login"/> </p>
        <p>   Password: <input type="text" name="password"/> <input type="submit" value="Ok"> </p>
    </form>
    <br>
    <form action="/signup">
        <button type = "submit"> button for registration</button>
    </form>');
TylerH
  • 20,799
  • 66
  • 75
  • 101
  • 4
    Some basic JS syntax tutorials might be in order; that's not how you do multi-line strings. There will be other issues as well, but at least start with some language basics. – Dave Newton Mar 25 '17 at 17:05

2 Answers2

2

Stay away from printing HTML that way please, but using ES6 back ticks should fix this issue.

document.write(`
    <p>Sign in</p>
    <form action="/chat" method="GET">
     <p> Login: <input type="text" name="login"/> </p>
     <p>   Password: <input type="text" name="password"/> <input type="submit" value="Ok"> </p>
    </form>
    <br>
    <form action="/signup">
     <button type = "submit"> button for registration</button>
    </form>
`);
realappie
  • 4,656
  • 2
  • 29
  • 38
0

You can't put enters in function code because interpreter thinks this is new line of code. Check that:

document.write('<p>Sign in</p><form action="/chat" method="GET"><p> Login: <input type="text" name="login"/> </p><p>   Password: <input type="text" name="password"/> <input type="submit" value="Ok"> </p></form><br><form action="/signup"><button type = "submit"> button for registration</button</form>');
Karol Jankiewicz
  • 153
  • 1
  • 12