Quotes problem

They have: 21 posts

Joined: Nov 2004

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.

Thanks in advance - Ted

DarkLight's picture

He has: 287 posts

Joined: Oct 2007

Try using single quotes, (apostrophes)...

class='edleft'

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.