1

I am going cross-eyed trying to figure out my syntax error here.

I have a table that I create dynamically. The user can click on one cell in a row to get an alert with notes in it.

The problem is that my quote marks are incorrect no matter what I do. I'm obviously not seeing something.

This PHP code

"<td onclick='showNotes()' ></td>";

Gets me in my HTML code upon rendering

<td onclick="showNotes()"></td>

This looks good and executes my jQuery no problem. So far so good.

========================================================

This PHP code (where $col contains the notes to be displayed)

"<td onclick='showNotes(" . $col . ")' ></td>";

gets me this in my HTML

<td onclick="showNotes(myNewNotes)"></td>

The only problem here is that myNewNotes is a string and needs to have quotes around it, or else I get an error that it is not defined. OK, moving along.

========================================================

So now I try this PHP code

"<td onclick='showNotes(" . "'" . $col . "'" . "')' ></td>";

Which gets me this in the HTML, which is crap.

<td onclick="showNotes(" myNewNotes'')'></td>

=========================================================

WHAT is going on?

0

3 Answers 3

4

You can escape quotes within your string, which will get you what you need:

"<td onclick='showNotes(\"$col\")' ></td>";
Sign up to request clarification or add additional context in comments.

1 Comment

YES! Thank you so much.
0

Normally you should use escape \ this way

  "<td onclick='showNotes(\'" .  $col ."\');' ></td>";

Comments

0

How about this

    echo "td onclick='showNotes(" .'"'. $col .'"'. ")' ></td>";

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.