Hi, I have a JS HTML editor (not a WYSIWYG) that I downloaded and it works fine, except that any input with quotes causes it to break. I need the quotes for things like HTML and CSS classes etc.
If I have quotes inside the onClick, it fails completely with an Object expected error. If the quotes are escaped with a \, I get an “unterminated string constant” error, with this showing where a button should be
','
','body')">
Tried
class=edleft --- works
class="edleft" --- errors
class=\\"edleft\\" --- errors
This is what I have now:
One of the JS button and the doAddTags function.
// the button code (example)
document.write("<img class=\\"edbutton\\" src=\\"/rail/edim/lft.gif\\" name=\\"btnCode\\" title=\\"Align left\\" onClick=\\"doAddTags('<div class=edleft>','</div>','" + obj + "')\\">");
// the bit that handles the onClick
function doAddTags(tag1,tag2,obj) {
textarea = document.getElementById(obj);
// Code for IE
if (document.selection) {
textarea.focus();
var sel = document.selection.createRange();
//alert(sel.text);
sel.text = tag1 + sel.text + tag2;
} else {
// Code for Mozilla
var len = textarea.value.length;
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var scrollTop = textarea.scrollTop;
var scrollLeft = textarea.scrollLeft;
var sel = textarea.value.substring(start, end);
//alert(sel);
var rep = tag1 + sel + tag2;
textarea.value = textarea.value.substring(0,start) + rep + textarea.value.substring(end,len);
textarea.scrollTop = scrollTop;
textarea.scrollLeft = scrollLeft;
}}
I hope someone can help on this as I’m not much on Javascript and a solution would allow me a lot more scope for button handling in the editor.
Do you have a link to where we can see the code in action as normally when it returns an error such as “Object expected” its associated with another part of the code trying to be executed.
Hi Philip, that gave me the same result as the broken body bit.
SgtLegend
I’ve only just got back in after a day away and it’s near on midnite in London, so what I’ll do it stick up a mock thing tomorrow and get back to you.
Thanks Philip, The quote entity works, I also tried out a numbered entity (#34) and that works too
I use numbered entities throughout as EezyBlog (the blog script I’ve written) is aimed at programmers and I wanted to handle all the ASCII characters that would work for non-English browsers as well.
Some quick tests saw the correct " in my entries and database.