0

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.

Edited by venkyb47

3
Contributors
3
Replies
6
Views
4 Years
Discussion Span
Last Post by venkyb47
2

Have you tried:

onclick="showRemarks('<?php echo $activityid ?>');"

Edited by JayJ

Votes + Comments
you got me for a few seconds :-)
3

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>
Votes + Comments
Same solution as I offered :)
0

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>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.