Note that there are some explanatory texts on larger screens.

plurals
  1. POCorrect syntax using JS 'onclick' functions inside PHP echo statements AND with embedded XML fetching
    primarykey
    data
    text
    <p>I am likely to get b'*ch slapped because I haven't searched the forum enough before posting, but I really think I searched all relevant posts already, many seem not specifically covering the question I have, the others fly right over my beginner's head ( as I am new to PHP &amp; js ). That being said...</p> <p>I have built a PHP code to fetch data from an XML file using the <code>$xml=simplexml_load_file();</code></p> <p>No worries there, however one of the needed data 'entries' or 'fields' needs to exist within an <code>onclick</code> and/or an <code>onmouseup</code> javascript function.</p> <p>The code is as follows:</p> <pre><code>&lt;?php $xml=simplexml_load_file('prod_test_feed_sameday.xml'); $max = 8; $i = 1; foreach($xml-&gt;product as $feed){ if ($i &lt;= $max){ echo "&lt;table id='{$feed-&gt;position}' class='prod_container'&gt; &lt;td class='hidden_mask' id='{$feed-&gt;position}'&gt; &lt;/td&gt; &lt;td class='hidden_image' id='{$feed-&gt;position}'&gt;&lt;span style='background:url({$feed-&gt;prod_image_large}) no-repeat center;'/&gt;&lt;/span&gt;&lt;div&gt;&lt;a onmouseup='$('.hidden_image#{$feed-&gt;position}').slideToggle('slow');' onclick='$('.hidden_mask#{$feed-&gt;position}').hide();'&gt;&lt;b&gt;CLOSE&lt;/b&gt;&lt;/a&gt;&lt;/div&gt; &lt;/td&gt; &lt;tr&gt; &lt;td class='prod_image' id='{$feed-&gt;position}'&gt; &lt;span style='background:url({$feed-&gt;prod_image_small}) no-repeat center; background-size:contain;'/&gt;&lt;/span&gt; &lt;/td&gt; &lt;td rowspan='1' class='info_toggle' id='{$feed-&gt;position}'&gt;&lt;a onmouseup='$('.hidden_image#{$feed-&gt;position}').slideToggle('slow');' onclick='$('.hidden_mask#{$feed-&gt;position}').show();&gt;&lt;img src='images/zoom_02.png' title='See a larger image of these flowers' /&gt;&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan='2' class='prod_name' id='{$feed-&gt;position}'&gt;{$feed-&gt;prod_name} &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan='2' class='prod_price' id='{$feed-&gt;position}'&gt;&lt;span id='{$feed-&gt;position}'&gt;from: £{$feed-&gt;price}&lt;/span&gt;&lt;a href='{$feed-&gt;prod_link}' target='_blank'&gt;&lt;span class='buy_button'&gt;&amp;nbsp;Buy it now!&amp;nbsp;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;"; $i++; } } ?&gt; </code></pre> <p>The data and the CSS all work perfectly. There is a <code>href</code> link towards the end of the code, which also works perfectly.</p> <p>I am racking my brain trying to find the error in my syntax within the <code>onlick</code> function.</p> <p>I have tried all manners of backslashing, using trial and error, for exampel:</p> <p><code>onclick='$(\'.hidden_mask#{$feed-&gt;position}\').hide();'</code> or <code>onclick='\'$('.hidden_mask#{$feed-&gt;position}').hide();\''</code> or <code>onclick=\''$(\'.hidden_mask#{$feed-&gt;position}\').hide();\''</code> or even <code>onclick=\''$(\\'.hidden_mask#{$feed-&gt;position}\\').hide();\''</code> &lt;--Freddy Krugar 'slashing' example</p> <p>At any rate I am at a loss.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload