Problem passing Variable from Javascript Function Constructed inside PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sunnypirate
    New Member
    • Aug 2009
    • 5

    Problem passing Variable from Javascript Function Constructed inside PHP

    The following code treats abcd as a variable and gives the error variable undefined in firebug
    Code:
    return $data = "<a href='#' onclick='ajaxcall(abcd);'>".$name."</a>";
    The following code gives the error XML Parsing Error at 1:44. Error 73: > required
    Code:
    return $data = "<a href='#' onclick='ajaxcall('abcd');'>".$image.$tmp->name."</a>";
    I also have tried typecasting, taking abcd inside another PHP variable then passing the PHP variable. None seem to work.

    Thank you for your help.
    Regards,
    Sunny.
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Code:
     
    $data = <<<EOD 
    <a href="#" onclick="ajaxcall('abcd')">.$name.</a>
    EOD;
    Give this a try. Using the heredoc syntax, it lets you get around having to escape quotes.

    Comment

    • sunnypirate
      New Member
      • Aug 2009
      • 5

      #3
      Thanks JKing!

      It worked. Awesome.

      Comment

      Working...