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; }
2

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Wouldn't escaping that forward slash be easier? like this: var generatedCode = "<script> <\/script> hello";
@JasonSperske Yes, it would. Added.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.