what is the error in:window.opener.document.EditView+".participant_id_"+index.value= id;?

A

Alex Luya

I wan to use a function(blow) to set value for an elment of parent
window,and the id of this element is a combination of string
+variable,the question is how to contruct this id,when I create it as
blow,got an error:invalid assignment left-hand side(firebug) ,So can
anybody help me?
---------------------------------------------------------------------------------------------------------------------------------------
function setUser(index,id){
window.opener.document.EditView+".participant_id_"+index.value =
id;
window.close();
}
----------------------------------------------------------------------------------------------------------------------------------------
 
R

RobG

I wan to use a function(blow) to set value for an elment of parent
window,and the id of this element is a combination of string
+variable,the question is how to contruct this id,when I create it as
blow,got an error:invalid assignment left-hand side(firebug) ,So can
anybody help me?

How to use strings to access object properties is explained in the
FAQ:

--------------------------------------------------------------------------- ------------------------------------------------------------
function setUser(index,id){
                 window.opener.document.EditView+".participant_id_"+index.value =
id;
                 window.close();}

Presumably EditView is the name of a form element and you are setting
the value of a form control whose ID starts with 'participant_id'. If
that is so, then:

var form = window.opener.document.forms['EditView'];
form['participant_id' + index].value = id;


may do the trick, it would be more robust to check the existence of
each object before attempting to access its properties. Some objects
can be assumed to exist with reasonable safety, e.g.

var win = window.opener;
var form = win.document.forms['EditView'];
var el = form['participant_id' + index];
if (el) {
el.value = id;
}

Untested, let us know how you get on.
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top