Hi,

I am trying to do something like this:

function showContent(toPopulate) { 
      document.getElementById(toPopulate).innerHTML = "<a href='javascript:showOtherContent(toPopulate);'>show</a>" 
}

function showOtherContent(toPopulate) {...}

I am not able to send the variable toPopulate as an argument of function showOtherContent() in line 2

Thanks,

Blaise

function showContent(toPopulate)
{ 
document.getElementById(toPopulate).innerHTML = "<a href='javascript:showOtherContent(\"toPopulate\");'>show</a>" 
}

function showOtherContent(toPopulate) {alert(toPopulate)}

Above is working

function showContent(toPopulate)
{ 
document.getElementById(toPopulate).innerHTML = "<a href='javascript:showOtherContent(\"toPopulate\");'>show</a>" 
}

function showOtherContent(toPopulate) {alert(toPopulate)}

Above is working

mahavir123,

showOtherContent(\"toPopulate\"); will send toPopulate as a string, and therefore alert(toPopulate) will print the string "toPopulate" and not the content of function argument - toPopulate. I need the content of toPopulate ...

Try this one:

document.getElementById(toPopulate).innerHTML = "<a href='javascript:showOtherContent(\"" + toPopulate + "\");'>show</a>"

Hope this help.

Try this one:

document.getElementById(toPopulate).innerHTML = "<a href='javascript:showOtherContent(\"" + toPopulate + "\");'>show</a>"

Hope this help.

It works. This is the solution.

Thanks Zero13

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.