Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery collects 2 points of data, even though only one is assigned
    primarykey
    data
    text
    <p>Quick question on the <code>.data()</code> in jQuery: My variable "valone" reaches into a dropdown menu within some HTML for the "data-whatever" value in the dropdown and then plugs it into the jQuery equation. But it also seems to be getting the "option value" value from the dropdown and includes it into the math somehow, even though I don't specify it to do so...</p> <pre><code>var valone = $('#os0 option:selected').data('whatever'); </code></pre> <p>Am I missing something in this <code>.data()</code> function? Or do I have something extra that is not necessary? (I have the complete jQuery and HTML below.)</p> <p><strong>jQuery</strong></p> <pre><code>$(document).ready(function(){ var valone = $('#os0 option:selected').data('whatever'); var valtwo = $('#os1').val(); var valthree = $('#os2').val(); var total = ((valone * 1) * (valtwo * 1) * (valthree * 1)); $('.calc').each(function(){ if($(this).val() != '') { total += parseInt($(this).val()); } }); </code></pre> <p><strong>HTML</strong></p> <pre><code>&lt;select style="width: 190px;" class="calc" name="os0" id="os0" type="text"&gt; &lt;option value="250" data-whatever="5"&gt;250 &lt;/option&gt; &lt;option value="500" data-whatever="6"&gt;500 &lt;/option&gt; &lt;option value="1000" data-whatever="7"&gt;1000 &lt;/option&gt; &lt;option value="2000" data-whatever="8"&gt;2000 &lt;/option&gt; &lt;option value="5000" data-whatever="9"&gt;5000 &lt;/option&gt; &lt;/select&gt; </code></pre> <p>Any help or advice would be greatly appreciated! </p>
    singulars
    1. This table or related slice is empty.
    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