tags:

views:

290

answers:

5

Dear all,
I have a javascript function pop_item I have to call this from PHP, so my PHP code is the following:

       echo '<a href="javascript:pop_item('.$_code.',1)">Link </a>';

It provides no error, but pop_item is not functioning,

The HTML output for the above is:

       <a href="javascript:pop_item('ABC',1)">Link </a>
+5  A: 

I think the problemn is in the pop_item function since the call seems to be correct, try this:

echo " <a href='#' onclick=\"pop_item(".$_code."', 1)\">link</a>";

or

echo '<a href="javascript:alert('.$_code.')">Link</a>';

see if that works.

Pim Jager
Judging from the HTML output, $_code already has quotes in it (assuming that the HTML output is accurate!).
Greg
Ah ok, that's possible, didn't think of that.
Pim Jager
Thanks Pim Jager , Now Working Fine
venkatachalam
@venkatachalam: Then you should accept his answer. :-)
Ben Blank
A: 

Your function is probably not defined... Make sure you included it somewhere...

m_oLogin
on Firefox's Error Console, that would pop up an error of "pop_item() is not defined"
Adriano Varoli Piazza
A: 

Is it actually PHP's problem? What happens if you 'hardcode' the same link in HTML? Does the function work then?

Adriano Varoli Piazza
A: 

If the output looks correct, then PHP has done its job correctly and the problem is in your javascript. Try running your page with Firebug, or some other javascript debugger to find the problem.

nickf
+2  A: 

if your pop_item function accepts a string as its first parameter, this could happen because of missing some quote characters there. use PHP's interpolation feature, so you could be sure which quote is which. something like this line:

 echo "<a href=\"javascript: pop_item('$_code',1);\">Link</a>";

if the pop_item accepts some other data type, then the single quotes are needless. I also recommend to use you browser's javascript error console to see what the details of the problem are.

farzad