S
soup_or_power
Hello All:
I'm having a whale of a problem with the following code. When the words
beginning with sugg contain an escaped single-quote (\' ==> back-slash
followed by quote) the script causes an error. How can I preserve the
single quote. Please review the code below and let me know. Many
thanks!
function clicker( but_id, sugg0, sugg1, sugg2, sugg3, sugg4, sugg5,
copy_type, p1) {
var suggx;
if (p1 ==1) suggx=sugg1;
else if (p1 ==2) suggx=sugg2;
else if (p1 ==3) suggx=sugg3;
else if (p1==4) suggx=sugg4;
else suggx=sugg5;
eval("document.forms[0]." + but_id + ".value='" + suggx +
"'");
eval("document.forms[0]." + but_id +
".style.backgroundColor='#ffffff'");
eval("document.forms[0]." + but_id +
".style.color='#000000'");
//alert("in clicker");
var cont;
if (copy_type.indexOf("HTML_COPY") > -1) {
cont =document.forms[0].HTML_COPY.value;
//alert("conthtml=" + cont);
//alert("sugg0=" + sugg0);
var
txt="document.forms[0].HTML_COPY.value=cont.replace(/" + sugg0 + "/" +
replaceOpts + ",'" + suggx + "')";
eval(txt);
//alert( document.forms[0].HTML_COPY.value);
} else {
cont =document.forms[0].AOL_COPY.value;
//alert("contaol=" + cont);
//alert("sugg0=" + sugg0 + " suggx= " + suggx + "
replaceOpts=" + replaceOpts);
var
txt="document.forms[0].AOL_COPY.value=cont.replace(/" + sugg0 + "/" +
replaceOpts + ",'" + suggx + "')";
eval(txt);
//alert( document.forms[0].AOL_COPY.value);
//alert( document.forms[0].AOL_COPY.value);
}
return true;
}
function showSugg(but_id, sugg0, sugg1, sugg2, sugg3, sugg4, sugg5,
copy_type) {
if (sugg0.indexOf("'") > -1) sugg0=replaceAll(sugg0, "'",
"\'");
if (sugg1.indexOf("'") > -1) sugg1=replaceAll(sugg1, "'",
"\'");
if (sugg2.indexOf("'") > -1) sugg2=replaceAll(sugg2, "'",
"\'");
if (sugg3.indexOf("'") > -1) sugg3=replaceAll(sugg3, "'",
"\'");
if (sugg4.indexOf("'") > -1) sugg4=replaceAll(sugg4, "'",
"\'");
if (sugg5.indexOf("'") > -1) sugg5=replaceAll(sugg5, "'",
"\'");
display=window.open('','_blank','menubar=0,location=no,status=no,directories=no,toolbar=no,scrollbars=no,height=220,width=250')
var screen_height = window.screen.availHeight;
var screen_width = window.screen.availWidth;
var left_point = parseInt(screen_width / 2);
var top_point = parseInt(screen_height/2);
display.moveTo(left_point, top_point);
display.focus();
//alert("display elements" + display.document.elements);
alert("sugg1" + sugg1 + "2" + sugg2 + "3" + sugg3 + "4" +
sugg4 + "5" + sugg5);
if (sugg1)
var message="<HTML><BODY><font face='verdana, arial,
helvetica, san-serif' size='2'><form><table>";
message += "<tr><td>" + sugg1 + "</td> <td><input
type=checkbox name=mycheck1 value=\"" + sugg1 +
"\" onClick=\'self.opener.clicker(\"" + but_id + "\",\"" +
sugg0 + "\",\""
+ sugg1 + "\",\"" + sugg2 + "\",\"" + sugg3 + "\",\"" + sugg4
+ "\",\"" + sugg5 +
"\",\"" + copy_type + "\", 1);"
+ "document.forms[0].mycheck2.checked=false;"
+
"document.forms[0].mycheck3.checked=false;document.forms[0].mycheck4.checked=false;"
+ "document.forms[0].mycheck5.checked=false;"
+ "\'></td></tr>";
if (sugg2)
message += "<tr><td>" +sugg2 + " </td><td><input type=checkbox
name=mycheck2 value=\"" + sugg2 +
"\" onClick=\'self.opener.clicker(\"" + but_id + "\",\"" +
sugg0 + "\",\""
+ sugg1 + "\",\"" + sugg2 + "\",\"" + sugg3 + "\",\"" + sugg4
+ "\",\"" + sugg5 +
"\",\"" + copy_type + "\", 2);"
+ "document.forms[0].mycheck1.checked=false;"
+
"document.forms[0].mycheck3.checked=false;document.forms[0].mycheck4.checked=false;"
+ "document.forms[0].mycheck5.checked=false;"
+ "\'></td></tr>";
if (sugg3)
message += "<tr><td>" +sugg3 + " </td><td><input type=checkbox
name=mycheck3 value=\"" + sugg3 +
"\" onClick=\'self.opener.clicker(\"" + but_id + "\",\"" +
sugg0 + "\",\""
+ sugg1 + "\",\""+ sugg2 + "\",\"" + sugg3 + "\",\"" + sugg4 +
"\",\"" + sugg5 +
"\",\"" + copy_type + "\", 3);"
+ "document.forms[0].mycheck2.checked=false;"
+
"document.forms[0].mycheck1.checked=false;document.forms[0].mycheck4.checked=false;"
+ "document.forms[0].mycheck5.checked=false;"
+ "\'></td></tr>";
if (sugg4)
message += "<tr><td>" +sugg4 + " </td><td><input
type=checkbox name=mycheck4 value=\"" + sugg4 +
"\" onClick=\'self.opener.clicker(\"" + but_id + "\",\""+
sugg0 + "\",\""
+ sugg1 + "\",\""+ sugg2 + "\",\"" + sugg3 + "\",\"" + sugg4 +
"\",\"" + sugg5 +
"\",\"" + copy_type + "\", 4);"
+ "document.forms[0].mycheck2.checked=false;"
+
"document.forms[0].mycheck3.checked=false;document.forms[0].mycheck1.checked=false;"
+ "document.forms[0].mycheck5.checked=false;"
+ "\'></td></tr>";
if (sugg5)
message += "<tr><td>" +sugg5 + " </td><td><input
type=checkbox name=mycheck5 value=\"" + sugg5 +
"\" onClick=\'self.opener.clicker(\"" + but_id + "\",\"" +
sugg0 + "\",\""
+ sugg1 + "\",\"" + sugg2 + "\",\"" + sugg3 + "\",\"" + sugg4
+ "\",\"" + sugg5
+ "\",\"" + copy_type + "\", 5);"
+ "document.forms[0].mycheck2.checked=false;"
+
"document.forms[0].mycheck3.checked=false;document.forms[0].mycheck4.checked=false;"
+ "document.forms[0].mycheck1.checked=false;"
+ "\'></td></tr>";
message += "<tr><td> <input type=\"button\" class=\"btn\"
name=\"Replace\" value=\"Replace\"
onclick=\"self.opener.replaceOpts=\'i\'\"></td>";
message += "<td> <input type=\"button\" class=\"btn\"
name=\"Replace All\" value=\"Replace All\"
onclick=\"self.opener.replaceOpts=\'ig\'\"></td>";
message += "<td> <input type=\"button\" class=\"btn\"
name=\"Done\" value=\"Done\"
onclick=\"self.opener.display.close()\"></td></tr>";
message += "</table></font>";
alert(message);
display.document.open();
display.document.write(message + "</BODY></HTML>");
display.document.close();
}
I'm having a whale of a problem with the following code. When the words
beginning with sugg contain an escaped single-quote (\' ==> back-slash
followed by quote) the script causes an error. How can I preserve the
single quote. Please review the code below and let me know. Many
thanks!
function clicker( but_id, sugg0, sugg1, sugg2, sugg3, sugg4, sugg5,
copy_type, p1) {
var suggx;
if (p1 ==1) suggx=sugg1;
else if (p1 ==2) suggx=sugg2;
else if (p1 ==3) suggx=sugg3;
else if (p1==4) suggx=sugg4;
else suggx=sugg5;
eval("document.forms[0]." + but_id + ".value='" + suggx +
"'");
eval("document.forms[0]." + but_id +
".style.backgroundColor='#ffffff'");
eval("document.forms[0]." + but_id +
".style.color='#000000'");
//alert("in clicker");
var cont;
if (copy_type.indexOf("HTML_COPY") > -1) {
cont =document.forms[0].HTML_COPY.value;
//alert("conthtml=" + cont);
//alert("sugg0=" + sugg0);
var
txt="document.forms[0].HTML_COPY.value=cont.replace(/" + sugg0 + "/" +
replaceOpts + ",'" + suggx + "')";
eval(txt);
//alert( document.forms[0].HTML_COPY.value);
} else {
cont =document.forms[0].AOL_COPY.value;
//alert("contaol=" + cont);
//alert("sugg0=" + sugg0 + " suggx= " + suggx + "
replaceOpts=" + replaceOpts);
var
txt="document.forms[0].AOL_COPY.value=cont.replace(/" + sugg0 + "/" +
replaceOpts + ",'" + suggx + "')";
eval(txt);
//alert( document.forms[0].AOL_COPY.value);
//alert( document.forms[0].AOL_COPY.value);
}
return true;
}
function showSugg(but_id, sugg0, sugg1, sugg2, sugg3, sugg4, sugg5,
copy_type) {
if (sugg0.indexOf("'") > -1) sugg0=replaceAll(sugg0, "'",
"\'");
if (sugg1.indexOf("'") > -1) sugg1=replaceAll(sugg1, "'",
"\'");
if (sugg2.indexOf("'") > -1) sugg2=replaceAll(sugg2, "'",
"\'");
if (sugg3.indexOf("'") > -1) sugg3=replaceAll(sugg3, "'",
"\'");
if (sugg4.indexOf("'") > -1) sugg4=replaceAll(sugg4, "'",
"\'");
if (sugg5.indexOf("'") > -1) sugg5=replaceAll(sugg5, "'",
"\'");
display=window.open('','_blank','menubar=0,location=no,status=no,directories=no,toolbar=no,scrollbars=no,height=220,width=250')
var screen_height = window.screen.availHeight;
var screen_width = window.screen.availWidth;
var left_point = parseInt(screen_width / 2);
var top_point = parseInt(screen_height/2);
display.moveTo(left_point, top_point);
display.focus();
//alert("display elements" + display.document.elements);
alert("sugg1" + sugg1 + "2" + sugg2 + "3" + sugg3 + "4" +
sugg4 + "5" + sugg5);
if (sugg1)
var message="<HTML><BODY><font face='verdana, arial,
helvetica, san-serif' size='2'><form><table>";
message += "<tr><td>" + sugg1 + "</td> <td><input
type=checkbox name=mycheck1 value=\"" + sugg1 +
"\" onClick=\'self.opener.clicker(\"" + but_id + "\",\"" +
sugg0 + "\",\""
+ sugg1 + "\",\"" + sugg2 + "\",\"" + sugg3 + "\",\"" + sugg4
+ "\",\"" + sugg5 +
"\",\"" + copy_type + "\", 1);"
+ "document.forms[0].mycheck2.checked=false;"
+
"document.forms[0].mycheck3.checked=false;document.forms[0].mycheck4.checked=false;"
+ "document.forms[0].mycheck5.checked=false;"
+ "\'></td></tr>";
if (sugg2)
message += "<tr><td>" +sugg2 + " </td><td><input type=checkbox
name=mycheck2 value=\"" + sugg2 +
"\" onClick=\'self.opener.clicker(\"" + but_id + "\",\"" +
sugg0 + "\",\""
+ sugg1 + "\",\"" + sugg2 + "\",\"" + sugg3 + "\",\"" + sugg4
+ "\",\"" + sugg5 +
"\",\"" + copy_type + "\", 2);"
+ "document.forms[0].mycheck1.checked=false;"
+
"document.forms[0].mycheck3.checked=false;document.forms[0].mycheck4.checked=false;"
+ "document.forms[0].mycheck5.checked=false;"
+ "\'></td></tr>";
if (sugg3)
message += "<tr><td>" +sugg3 + " </td><td><input type=checkbox
name=mycheck3 value=\"" + sugg3 +
"\" onClick=\'self.opener.clicker(\"" + but_id + "\",\"" +
sugg0 + "\",\""
+ sugg1 + "\",\""+ sugg2 + "\",\"" + sugg3 + "\",\"" + sugg4 +
"\",\"" + sugg5 +
"\",\"" + copy_type + "\", 3);"
+ "document.forms[0].mycheck2.checked=false;"
+
"document.forms[0].mycheck1.checked=false;document.forms[0].mycheck4.checked=false;"
+ "document.forms[0].mycheck5.checked=false;"
+ "\'></td></tr>";
if (sugg4)
message += "<tr><td>" +sugg4 + " </td><td><input
type=checkbox name=mycheck4 value=\"" + sugg4 +
"\" onClick=\'self.opener.clicker(\"" + but_id + "\",\""+
sugg0 + "\",\""
+ sugg1 + "\",\""+ sugg2 + "\",\"" + sugg3 + "\",\"" + sugg4 +
"\",\"" + sugg5 +
"\",\"" + copy_type + "\", 4);"
+ "document.forms[0].mycheck2.checked=false;"
+
"document.forms[0].mycheck3.checked=false;document.forms[0].mycheck1.checked=false;"
+ "document.forms[0].mycheck5.checked=false;"
+ "\'></td></tr>";
if (sugg5)
message += "<tr><td>" +sugg5 + " </td><td><input
type=checkbox name=mycheck5 value=\"" + sugg5 +
"\" onClick=\'self.opener.clicker(\"" + but_id + "\",\"" +
sugg0 + "\",\""
+ sugg1 + "\",\"" + sugg2 + "\",\"" + sugg3 + "\",\"" + sugg4
+ "\",\"" + sugg5
+ "\",\"" + copy_type + "\", 5);"
+ "document.forms[0].mycheck2.checked=false;"
+
"document.forms[0].mycheck3.checked=false;document.forms[0].mycheck4.checked=false;"
+ "document.forms[0].mycheck1.checked=false;"
+ "\'></td></tr>";
message += "<tr><td> <input type=\"button\" class=\"btn\"
name=\"Replace\" value=\"Replace\"
onclick=\"self.opener.replaceOpts=\'i\'\"></td>";
message += "<td> <input type=\"button\" class=\"btn\"
name=\"Replace All\" value=\"Replace All\"
onclick=\"self.opener.replaceOpts=\'ig\'\"></td>";
message += "<td> <input type=\"button\" class=\"btn\"
name=\"Done\" value=\"Done\"
onclick=\"self.opener.display.close()\"></td></tr>";
message += "</table></font>";
alert(message);
display.document.open();
display.document.write(message + "</BODY></HTML>");
display.document.close();
}