• 0

[Javascript] variable function into onclick


Question

I have a situation where I need to replace a function dynamically

The function is usually:

showItemDetails('"+iRow+"','1','"+iID1+"')"

grdSelectItems.addRow(iRow,["<a href='#' title='"+sToolTip1+"' style='color:"+sColor+";font-family:Arial;font-weight:bold;font-size:9pt;text-decoration:none;' onclick=\"showItemDetails('"+iRow+"','1','"+iID1+"');\">"+sItem1+"</a>)

However I sometimes need to call the function showVendorClosed(iID);

I tried placing the first function in it's own string but that died a horrible death:

var sFunction = "showItemDetails('"+iRow+"','1','"+iID1+"')"

grdSelectItems.addRow(iRow,["<a href='#' title='"+sToolTip1+"' style='color:"+sColor+";font-family:Arial;font-weight:bold;font-size:9pt;text-decoration:none;' onclick=\'"+sFunction+";\">"+sItem1+"</a>)

Thoughts?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Looks like this could be a problem:

onclick=\'"

That single quote, together with your function string will end up like this:

onlick='showItemDetails('...')'

Replace that with this:

onclick=\"" + sFunction + "\"

That help?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.