I have an input which has a dynamic value as it's editable. Either Onkeypress in textarea or after onclick event fired on clicking the btn id it should append the input value in another iframe which is to be dynamic because input is to be changeable. So without page load the iframe's script innerHTML should refresh. I've done something but it's not working.
HTML
<textarea id="inpt" cols="30" rows="10"></textarea>
<div><input type="submit" value="append" id="btn" style="width:60px;height:20px;background:grey"></div><br>
<iframe id="fr" name="fr" style="width:300px;height:300px;"></iframe>
JS
var _script = document.createElement('script');
_script.type = 'text/javascript';
var iFrame = document.getElementById('fr'),
iFrameBody,
t = document.getElementById("inpt"),
btn = document.getElementById('btn');
function injectJS(content, val) {
if ( iFrame.contentDocument )
{
iFrameBody = iFrame.contentDocument.getElementsByTagName('body')[0];
}
else if ( iFrame.contentWindow )
{
iFrameBody = iFrame.contentWindow.document.getElementsByTagName('body')[0];
}
iFrameBody.appendChild(content);
content.innerHTML = val;
console.log(iFrameBody);
}
//t.onkeypress = injectJS(_script, t.value);
btn.onclick = injectJS(_script, t.value);
And here's the working demo. http://jsfiddle.net/n5fdywb9/