Execute dynamic HTML/JavaScript

Hi,

I’d like to create a textarea and a division so that whatever embed code you put in the textarea it gets executed on the division in real-time.

Your kind help is greatly appreciated!
JavaScript newbie

After hours searching and trying different approaches I came up to the following simple code:

<script type="text/javascript">
var X = " HTML or JavaScript "
window.onload=function()
{
document.getElementById("result").innerHTML = document.getElementById("input").value;
}
</script>

<textarea id="input" cols="35" rows="7"> X </textarea>

<div id="result"></div>

All I need is using eval function to get the whole code (HTML or JavaScript) as one variable. I wonder if someone can help me with this as I’m badly stuck!