How to write JS inside PHP code
<p>I have code like this:</p>

<pre><code>    &lt;?php if($key['caffe_id'] == echo "&lt;script&gt;$("#caffe").text()&lt;/script&gt;") ?&gt;
</code></pre>

<p>How to write this in correct manner?</p>

<p>Code for explanation:</p>

<pre><code>&lt;select name="caffe" id="caffe"&gt;
            &lt;?php foreach($caffe as $key) : ?&gt;
            &lt;option value="&lt;?php echo $key['id_caffe'] ?&gt;"&gt;&lt;?php echo $key['name'] ?&gt;&lt;/option&gt;
            &lt;?php endforeach; ?&gt;
        &lt;/select&gt;
        &lt;div id="gll_select"&gt;
            &lt;?php if (isset($gallery)) : ?&gt;
        &lt;select name="gll" id="gll"&gt;
    &lt;?php foreach ($gallery as $key) : ?&gt;
            &lt;?php if($key['caffe_id'] == echo "&lt;script&gt;$('#caffe').text()&lt;/script&gt;") : ?&gt;
        &lt;option value="&lt;?php echo $key['id_gallery'] . " " . $key['name'] ?&gt;"&gt;&lt;?php echo $key['name'] ?&gt;&lt;/option&gt;
        &lt;?php endif; ?&gt;
    &lt;?php endforeach; ?&gt;
        &lt;?php endif; ?&gt;
</code></pre>

<p>The first select will determine what data will be written in second one. I need to make default case when page is loaded and when first select (#caffe) is being changed.</p>
