I am unable to send a string from php page to java script page. I am storing a string in a php variable and I want to send this value to java script page on image icon click. Here is the source code:

timetrack.php

$activityid = $getResult->fields('ACTIVITY_ID');    // Now consider the value in $activityid is "AG001"
<img src="phpimages/tt_comment.gif" title="Add remarks" alt="add remarks icon" style="border:none;cursor:pointer;margin:0 0 0 5px" onclick="showRemarks('.$activityid.');" id="remarksadd"></img>

userfn.js

function showRemarks(actid)
{
alert(actid);
document.getElementById("tt_comment_section").value = actid;
}

Here the function showRemarks(actid) itself is not calling.
FYI: If I store integer value(ex: 256487) in $activityid variable, the function is calling successfully and alert is showing the result. Problem coming with the string alone. I have tried with different syntaxes like

onclick="showRemarks("'.$activityid.'");"
onclick="showRemarks('".$activityid."');"
onclick="showRemarks(".$activityid.");"
onclick="showRemarks($activityid);"

but no one giving result. Please give me the solution.
Thanks.

Have you tried:

onclick="showRemarks('<?php echo $activityid ?>');"
commented: you got me for a few seconds :-) +6

If you want to use a php variable in html enclose it within the <?php ?> tags and echo it:

onclick="showRemarks(' <?php echo $activityid; ?>');" id="remarksadd"></img>
commented: Same solution as I offered :) +1

Thanks for your reply JayJ and broj1. Your solution is correct. The mistake I have done is, forget to close php tag before html img tag. Here is the answer.

<?php
$activityid = $getResult->fields('ACTIVITY_ID');    // Now consider the value in $activityid is "AG001"
?>
<img src="phpimages/tt_comment.gif" title="Add remarks" alt="add remarks icon" style="border:none;cursor:pointer;margin:0 0 0 5px" onclick="showRemarks('<?php $activityid ?>');" id="remarksadd"></img>
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.