Nevermind, found a fix, just edited innerHTML
to value
.
Might come helpfull for some users.
Question
I'm working on my on Visual Text editor. It's working decently, preview works perfectly, and so does my JS appending. The HTML is this one:
<div class="wysiwyg">
<div class="wystitle">What You See Is What You Get<br>Editor by ShowTime</div>
<div class="wysmenu"><button class="wysbutton" onClick="addBold()">Bold</button><button class="wysbutton">Italic</button><button class="wysbutton">Underline</button><button class="wysbutton">Link</button><button class="wysbutton">Color</button><button class="wysbutton">Quote</button></</div>
<textarea rows="9" cols="145" id="wystext"></textarea><br>
<button class="wysbutton" onClick="preview()">Preview</button><button class="wysbutton">Post!</button>
</div>
<br><br><br><br><br><br><br><br><br><br><br>
<div class="wyspreview" id="wyspreview">Hit 'Preview' To See the Post General Look<br>Hit 'Post' To Create the Blog Post</div>
And I want to have the Bold button to simply add TEXT HERE. This is the JAvaScript:
function preview() {
var preview = document.getElementById("wystext").value;
document.getElementById("wyspreview").innerHTML = preview;
}
function addBold() {
var text = document.getElementById("wystext").value;
document.getElementById("wystext").innerHTML = text + "<strong></strong>";
var text = null;
}
The addBold function works properly, but as soon as I type in the text area, it won't work anymore. Any ideas why ?
La solution 2
Nevermind, found a fix, just edited innerHTML
to value
.
Might come helpfull for some users.
Autres conseils
You should put the text inside the tag:
"<strong>" + text + "</strong>"
It would also be helpful to incude a jsfiddle with an example.