onlick confirm function with different text from array
<p>I am having an issue with attempting to show different confirm text from an array when using a hyperlink. The text always ends up being from the last confirmation text in the array. I have seen 2 examples on this forum using a function() in a function but I was not able to get this working from viewing the examples.</p>

<p>Here is my code:</p>

<pre><code>echo '
&lt;script type="text/javascript"&gt;         
        function getDetails(message)
        {           
            if (confirm(message))
                return true;
            else
            {                   
                var links = document.getElementsByTagName("a");

                for(i=0;i&lt;links.length;i++) 
                    links[i].href = item_NoLink;
            }           
        }
    &lt;/script&gt;';

foreach ($items as $item)
{
    $link = 'http://test_url/mytest.php;report='. $item['id'];

            echo '
            &lt;script type="text/javascript"&gt;                 
                var item_detail = ', json_encode($item['reported_spam']['detail']),'
                var item_NoLink = ', json_encode('http://test_url/mytest.php;'),'                   
            &lt;/script&gt;
                &lt;a id="mylink[]" onclick="getDetails(item_detail);" href="'.$link.'" style="text-decoration:none;"&gt;
                    &lt;img id="myImage" alt="" src="http://test_url/images/reported.gif" title="'.$item['reported_spam']['title'].'" style="position:relative;border=0px;vertical-align:middle;right:5px;" /&gt;
                &lt;/a&gt;';

}
</code></pre>

<p>Thanks.</p>

<hr>

<p>Edit: I figured it out.</p>

<p>@Grant Zhu: Arrays are not written like that in php and one can progress to the next key just using the empty square brackets. You were correct as I did make an err for the image id array and the js variables. Also for php when using single quotes inside echo with single quotes one must use the backslash (unless using php again).</p>

<p>I got it working as such:</p>

<pre><code>echo '
&lt;script type="text/javascript"&gt;   
    var item_NoLink = ', json_encode('http://test_url/mytest.php;'),'         
    function getDetails(message)
    {           
        if (confirm(message))
            return true;
        else
        {                   
            var links = document.getElementsByTagName("a");

            for(i=0;i&lt;links.length;i++) 
                links[i].href = item_NoLink;
        }           
    }
&lt;/script&gt;';

foreach ($items as $item)
{
    $link = 'http://test_url/mytest.php?report='. $item['id'];

        echo '            
            &lt;a id="mylink[]" onclick="getDetails(\'',$item['reported_spam']['detail'],'\');" href="'.$link.'" style="text-decoration:none;"&gt;
                &lt;img id="myImage[]" alt="" src="http://test_url/images/reported.gif" title="'.$item['reported_spam']['title'].'" style="position:relative;border=0px;vertical-align:middle;right:5px;" /&gt;
            &lt;/a&gt;';

}
</code></pre>

<p>Thank you.</p>
