Sunday, 25 August 2013

Pass html object through string into function

Pass html object through string into function

What I have is kinda unusual I guess. I have this function deleteItem
which is triggered onclick and has the following parameters
function dItem(type,id,element,confirmed){
if(confirmed){
handle delete function
}else{
var c = ',';
popup('Are you sure you want to delete this item?',
{"Yes":"dItem("+type+c+id+c+element+c+true+")","Cancel":"popupClose()"}
)
}
}
.. onclick='dItem("comment",15,this,false)' ..
In popup()'s second parameter are passed the buttons that are to be
displayed in the popup and the functions they call respectively. The
problem is that element is a HTMLDIV element and I cannot figure out a
neat way to pass that through a string. The only solution I could come to
think of is to have a global variable holding the element in question and
not passing it at all, although I don't really want to do that since it's
more of a hack rather than a solution. Does anybody have any idea how I
can pass that element through a string? Thanks in advance!

No comments:

Post a Comment