2

I came up with an idea for a javascript thing that lets the user write in a message. Then they can click generate and it will show them code they can copy and paste onto a webpage to use.

I created the javascript program and it works great. Now I want to let the user fill in the form and generate the code. This is where im kinda stuck. I tried making a string var and making it equal the code (I put all the code on one line, got rid of the tags and left only the tags and the html code.

I will add the code to a textarea when it works but it does not seem to want to.

On my page: (generate is called when the user clicks a button)

 <script>

   function Generate()
  {
  var generatedCode = "<script> </script> hello";
  document.getElementById("codeArea").value = generatedCode;
  }
  </script>

in the html area:

 <textarea rows="6" cols="51" id="codeArea">

currently this shows up on the top of the page:

 hello"; document.getElementById("codeArea").value = generatedCode; }
R00059159
  • 171
  • 1
  • 7
  • 13

1 Answers1

2

The </script> tag in the script is interpreted as the end tag of your script, and

 hello";
 document.getElementById("codeArea").value = generatedCode;
 }

is interpreted as text, as it's outside the script. Try with

"<script> <\/script> hello"

or

"<script> </scr" + "ipt> hello"

</script> shouldn't appear inside a script, not even as part of a string literal.