-2

okay this is just so messed up to me i don't understand why, its doing this

My Onclick code is this

<a onclick="javascript:quote('<?php echo $dnn2['message']; ?>', '[quote=<?php echo $dnn2['author']; ?>]', '[/quote]', 'message');">quote</a>

my problem is its being echoed like this

brandon Wrote:
second comment on the topic
', '[quote=brandon]', '[/quote]', 'message');">quote

and i have no idea why it is, here is the page source

    <td class="left" style="min-height:100px;margin-left:100px;width:500px;border:solid 1px #2E2E2E;border-radius:5px;">
<div style="height:40px;margin-left:250px;margin-top:5px;width:250px;"><b>Date sent:</b> 2014/09/01 10:17:29</div>

   <div style="border:1px solid gray;"><div>brandon Wrote:</div> <div><span style="text-decoration:underline;"><strong>second comment on the topic</strong></span></div></div>
        <div class="edit">
         <a href="edit_message.php?id=1&id2=21">
            <img src="default/images/edit.png" alt="Edit" />
         </a>
      <a onclick="javascript:quote('<div style="border:1px solid gray;"><div>brandon Wrote:</div> <div><span style="text-decoration:underline;"><strong>second comment on the topic</strong></span></div></div>', '[quote=brandon]', '[/quote]', 'message');">quote</a>
</div>
    </td>
  • 1
    What do you expect to happen, and how is that different that the results you see now? – George Cummins Sep 01 '14 at 15:35
  • The `quote()` function just returns its argument with quotes around it and special characters escaped. It doesn't do anything visible with it. It's also a non-standard function that you probably shouldn't be using. – Barmar Sep 01 '14 at 15:40
  • It also doesn't take any arguments, it's called as `str.quote()`, not `quote(str)`. – Barmar Sep 01 '14 at 15:42
  • Looks an awful lot like you're confusing the client side and the server side of your app. PHP runs on the server, the javascript runs in the client's browser (if it runs at all) and neither side can directly affect the other. The client side can access variables set on the server side provided they're echoed out into the output but only the final values are available this way. Going toe other way required AJAX. – GordonM Sep 01 '14 at 16:04

2 Answers2

0

you could try something like to see if it works

<?php
echo "<a onclick=\"javascript:quote('".$dnn2['message']."', '[quote=".$dnn2['author']."]', '[/quote]', 'message');\">quote</a>";
?>

Or even just put raw values in there instead of the PHP to check that it isnt something wrong elsewhere.

Note: While the ". ." arent really neccessary since variables within " " still work, i find it helps with readability and variables highlight correctly in code editors such as PSPad.

EDIT

Your problem is

<a onclick="javascript:quote('<div style="border:1p

Your code is basically:

<a onclick="javascript:quote('<div style="

That is what is in the 'onclick' comment ending at the =" symbol. Escape ALL double-quotes (") that are within the onclick="..."

0

Given that you're already printing the post data to be quoted out in the quote links, I'd suggest a much cleaner route with jQuery.

First, make a two-dimensional array of poster and post contents data for each post (on the page). Then, make each link have a class name and another with iteration (example would be class="quote q1"). The iteration could also be an id so you don't have to substring anything (class="quote" id="1").

Add jQuery code for the .click(".quote") of your class which should fire the quote function based on the value of the secondary class or the iterated id. Grab the values for the quote function based on the contents of the array function at the index of the iterated class/id.

This approach would be much cleaner, easier to read, and more organized.

Chad
  • 1,531
  • 3
  • 20
  • 46