Note that there are some explanatory texts on larger screens.

plurals
  1. POPass variable to external js file via onClick in HTML
    text
    copied!<p>I want to be able to pass a variable to a JavaScript function. with the below onClick event. Basically every time the <code>onClick</code> is triggered for these images a <code>var</code> is expected to be sent to a the JavaScript function. So if image one is clicked I want to send:</p> <p><code>var myvar = "sof273561";</code> to <code>gotowebpage()</code></p> <p><code>gotowebpage()</code> function is in <code>show_details.js</code> file.</p> <pre><code>&lt;div class="furnitureTypes"&gt; &lt;!--- furniture image 1 --&gt; &lt;li&gt;&lt;div class="furniture"&gt;&lt;input type="image" src="images/furniture/1.jpg onClick="gotowebpage();"/&gt;&lt;gt_descA&gt;Sofas&lt;/gt_descA&gt;&lt;gt_descB&gt;$2050&lt;/gt_descB&gt;&lt;gt_descC&gt;&lt;a href="sofas_27356.pfd" target="_blank" style="color:#FF0000"&gt;Check catelog&lt;/a&gt;&lt;/gt_descC&gt;&lt;/div&gt;&lt;/li&gt; &lt;!--- furniture image 2 --&gt; &lt;li&gt;&lt;div class="furniture"&gt;&lt;input type="image" src="images/furniture/2.jpg onClick="gotowebpage();"/&gt;&lt;gt_descA&gt;Chairs&lt;/gt_descA&gt;&lt;gt_descB&gt;$420&lt;/gt_descB&gt;&lt;gt_descC&gt;&lt;a href="chairs_18119.pfd" target="_blank" style="color:#FF0000"&gt;Check catelog&lt;/a&gt;&lt;/gt_descC&gt;&lt;/div&gt;&lt;/li&gt; &lt;!--- furniture image 3 --&gt; &lt;li&gt;&lt;div class="furniture"&gt;&lt;input type="image" src="images/furniture/3.jpg onClick="gotowebpage();"/&gt;&lt;gt_descA&gt;Tables&lt;/gt_descA&gt;&lt;gt_descB&gt;$1300&lt;/gt_descB&gt;&lt;gt_descC&gt;&lt;a href="tables_15723.pfd" target="_blank" style="color:#FF0000"&gt;Check catelog&lt;/a&gt;&lt;/gt_descC&gt;&lt;/div&gt;&lt;/li&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;script src="js/show_details.js"&gt; &lt;/script&gt; </code></pre>
 

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