/    Sign up×
Community /Pin to ProfileBookmark

Why doesnt this work

<!Doctype html>
<html lang=”en-us”>
<head>
</head>
<body>
<textarea id=”code” style=”height:80%;width:50%;position:absolute;left:0%;bottom:0%;”onkeyup=”repeat()”></textarea>

<script type=”text/javascript”>
function repeat()
{
var code=”document.getElementById(“code”).value;
document.write(‘<frame id=”edited” style=”height:80%;width:50%;position:absolute;bottom:0%;right:0%;>’+code+'</frame>’);

}
</script>
</body>
</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@nathanwallApr 10.2012 — There's a few things wrong with it. There are some problems with the quotation marks. I think you meant to use an iframe instead of a frame tag. But most importantly, document.write doesn't really work the way you expect after the document loads.

I think this example does what you wanted:

[code=php]<!Doctype html>
<html lang="en-us">
<head>
</head>
<body>
<textarea id="code" style="height:80%;width:50%;position:absolute;left:0%;bottom:0%;" onkeyup="repeat()"></textarea>
<iframe id="edited" style="height:80%;width:50%;position:absolute;bottom:0%;right:0%;"></iframe>
<script type="text/javascript">
function repeat()
{
var code = document.getElementById('code').value;
var edited = document.getElementById('edited');
var doc = edited.contentDocument || edited.contentWindow.document;
doc.body.innerHTML = code;
}
</script>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@rtretheweyApr 10.2012 — There are at least two reasons why your code doesn't work. First, when you call document.write() after the page has loaded, it (usually) erases the document and starts over from scratch. You should use document.getElementById(??).innerHTML to manipulate the content of an element on your page. Second, you've misused the <frame> tag. Use <div> instead. And check the 'style' attribute for a missing last quotation mark.
×

Success!

Help @cplusplusjs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...