How do you make a box that can test code?

Today I was wondering how to make a box that I can test code with using some JavaScript and HTML. Example: Click Here. Here's what I want it to do: You enter code into the text box, then you click the "Test HTML Code" button and it opens in a new tab with the code that you type into the text box. I hope this is enough information.