error "Missing ] after element list" error in FireFox

S

soup_or_power

I'm passing the return from window.open as a function argument and
getting the error "missing ] after element list" when tested with
FireFox. Here is the relevant code. Many thanks for your help.

function blurCkbox(num, disp, but_id, sugg)
{
if (num == 1) {
eval("self.opener.document.forms[0]." + but_id + ".value=\'" +
sugg + "\'");

}
function showSugg(but_id, sugg1, sugg2, sugg3, sugg4, sugg5) {


var
display=window.open('','_blank','menubar=0,location=no,status=no,directories=no,toolbar=no,scrollbars=yes,height=110,width=190')
var message="<font face='verdana, arial, helvetica, san-serif'
size='2'><form>";
message += sugg1 + "<input type=checkbox name=mycheck1
value=\'" + sugg1 + "\' onClick=\"blurCkbox('1'," + display + "," +
but_id + ",\'" + sugg1 + "\')\">";

}
 
L

Lee

(e-mail address removed) said:
I'm passing the return from window.open as a function argument and
getting the error "missing ] after element list" when tested with
FireFox. Here is the relevant code. Many thanks for your help.

function blurCkbox(num, disp, but_id, sugg)
{
if (num == 1) {
eval("self.opener.document.forms[0]." + but_id + ".value=\'" +
sugg + "\'");

}

There's no need to use eval() there:

if (num == 1) {
opener.document.forms[0].elements[but_id].value=sugg;
}

I notice that blurCkbox has a formal parameter "disp" that
is never used.

function showSugg(but_id, sugg1, sugg2, sugg3, sugg4, sugg5) {


var
display=window.open('','_blank','menubar=0,location=no,status=no,directories=no,toolbar=no,scrollbars=yes,height=110,width=190')
var message="<font face='verdana, arial, helvetica, san-serif'
size='2'><form>";
message += sugg1 + "<input type=checkbox name=mycheck1
value=\'" + sugg1 + "\' onClick=\"blurCkbox('1'," + display + "," +
but_id + ",\'" + sugg1 + "\')\">";

}

You're not passing the return value of window.open() as a function
argument. You're concatinating it into a string named "message".
When you concatinate an Object (a Window object, in this case)
with strings, it is converted to a string by its toString() method.
The default method that would be used in this case converts the
Object to the string "[Object]", which creates a syntax error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top