parameter and nested functions

M

Mariano C.

I have a main function (Main) that accept 2 parameters (id_c & id_o),
inside this function another function is called (addEventListener).
Inside addEventListener is declared an anonymous function.

What I would is the possibility to use the above parameter inside this
anonymous function (exactly inside the attachment var). I've write
this, but is uncorrect:

function Main(id_c, id_o) {
var obj = document.getElementById('xyz');

obj.addEventListener(
'click',
function(id_c, id_o)
{
var attachment =
{
'media':
[
{
'type':'image',
'src': 'http://.../img/loghi/
32x32/'+id_c+'.png',
'href': 'http://.../img/loghi/
32x32/'+id_c+'.png'
},
{
'type':'image',
'src':'http://.../loghi/
32x32/'+id_o+'.png',
'href':'http://.../img/loghi/
32x32/'+id_o+'.png'
}
]
};
// ...
return false;
}, false
);
}

PS: if inside anonym function (just before attachment declaration) I
declare id_o and id_c the script is working. Only if I try to pass the
parameter starting from Main function I got an error!
Ideas???
 
M

Mariano C.

On 03/10/09 08:59, Mariano C. wrote:
If you want help, you'll need to provide a little more detail than "not
working". If it didn't "work", you're doing something you're not telling
us about.

The problem is inside my empty head, DAMN!
When I call Main function I pass a wrong variable as parameter. That's
why doesn't work. :(
Anyway information about callback is really usefull :)


Regards
 

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,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top