Forum Moderators: open
Any idea how to fix this in JavaScript? I know that in vb i can use Replace(var, "'", "''") but am not sure how to do it in JavaScript.
-----------------------------
oNewTd13.innerHTML = "<select class=copy style='background-color: #FFFFFF' onchange=\"document.forms[0].elements['linerTextAndDescriptionAdj_" + vid + "'].value = linerText + ' ' + this.options[this.selectedIndex].innerHTML; document.forms[0].elements['DescriptionAdj_" + vid + "'].value = this.options[this.selectedIndex].innerHTML; \" name=descript_" + vid + "><option value=''>-- choose description --</option>" + descriptionAdjOptions + "</select>";
function showPreview(vid) {
var oForm = document.forms[0];
var iNumElems = oForm.elements.length;
var oElem;
// Refresh the inner contents of divPreview with the most recent copy of linerText.
if (eval("document.forms[0].elements['linerTextAndDescriptionAdj_" + vid + "'].value")!= "") {
eval("divPreview" + vid + ".innerText = '" + eval("document.forms[0].elements['linerTextAndDescriptionAdj_" + vid + "'].value") + "'");
}
eval("divPreview" + vid + ".style.visibility = 'visible'");
for (var i=0;i<iNumElems;i++) {
oElem = oForm.elements[i];
if (("SELECT" == oElem.tagName) && (oElem.name!= "descript_" + vid)){
oElem.style.visibility = 'hidden';
}
}
}
Remove all single quotes in a string:
(need a RegExp else only the first will be removed)
str = str.replace(/'/g,'')
// could maybe escape the quote in the Regexp \', if your syntax highlighting goes off.
Don't use eval (more crazy quoting games)
eval("document.forms[0].elements['linerTextAndDescriptionAdj_" + vid + "'].value")
// to
document.forms[0].elements['linerTextAndDescriptionAdj_' + vid].value
AND (!)
eval("divPreview" + vid + ".innerText = '" + eval("document.forms[0].elements['linerTextAndDescriptionAdj_" + vid + "'].value") + "'"); // to
document.getElementById('divPreview' + vid ).innerText
= document.forms[0].elements['linerTextAndDescriptionAdj_' + vid ].value;