Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another noob question

Status
Not open for further replies.

BennySHS

Programmer
Mar 15, 2005
32
DE
Hi there,

first sorry for my senseless subjects, but I'm not able to explain this problem in a few words.

What I want to do:
I'm trying to code a little javasript-based html-editor.
So there is a big text-field where the User can enter his code. What I want is a preview of the html-code the User entered.
For example:
The user types in his Editor-box <b>test</b>, then I want to have another text-box (or iframe or whatever), where the user can the now a bold "test"-word.
I tried it this way:

onClick="javascript: document.getElementById('preview-box').value=document.getElementById('input-box').value"

But this way in the preview-box gets just the same text as the input-box, in my example <b>test></b> instead of the interpreted bold "test"-word.

Sorry for my strange english, I can't write that good, but I hope you can understand me anyway ^^
thx a lot,
greets ben
 

There are several ways to achieve this. This is one of the easier ones:

Code:
document.getElementById('previewBox').innerHTML = document.getElementById('inputBox').value;

...

<div id="previewBox"></div>
<input type="text" id="inputBox" />

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
like so:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]

<html>
<head>
<title>Untitled</title>

<script language="javascript"><!--

function preview() {
    var src = document.forms['codeForm'].elements['code'].value;
    var pre = document.getElementById('previewDiv');
    pre.innerHTML = src;
}

--></script>

</head>

<body>

<form name="codeForm">
  <textarea name="code"></textarea>
  <input type="button" onclick="preview();" value="Preview" />
</form>

<div id="previewDiv" style="border: 1px solid black;"></div>

</body>
</html>

*cLFlaVA
----------------------------
[tt]a frickin' twelve-gauge, what do you think?[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thank you very much!
Exactly what I wanted, and I expected that this would me much more complicated...
A very good answer in a very short time - great ! ;)
greets,
ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top