4

I am putting a html inside the php echo like .

echo '<td onclick="getdesc($descriptn)">';

My problem is onclick is not working i also tried like

echo '<td onclick="getdesc(\'$descriptn\')">';

But in this i am not geting the value of variable $descriptn is directly printing .

Please tell me what is the right way to do this ,

1
  • What about ?><td onclick="getdesc(<?= $descriptn ?>)"><? Commented Dec 20, 2012 at 7:33

5 Answers 5

4

Change to

echo '<td   style="margin-top: 3px; padding: 3px 2px; background: none repeat scroll 0px 0px #E9E9E9;" onclick="getdesc(\''.$descriptn.'\')" >';
Sign up to request clarification or add additional context in comments.

Comments

3

use double quote for this, that was the mistake.

echo "<td   style='margin-top: 3px; padding: 3px 2px; background: none repeat scroll 0px 0px #E9E9E9;' onclick='getdesc(\'$descriptn\')' >";

1 Comment

I also tried but this will not work if the descriptn value will be a string
1

Single quotes vs double quotes

echo '<td   style="margin-top: 3px; padding: 3px 2px; background: none repeat scroll 0px 0px #E9E9E9;" onclick="getdesc(\''.$descriptn.'\')" >';

Comments

0

Here's another approach without concatenating strings:

$description = "hello world";
echo "<td onclick=\"getdesc('$description')\">";

Comments

0
echo '<td onclick="getdesc('.$descriptn.')">';

You may add it like this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.