Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiply results using same function displayed on same page
    primarykey
    data
    text
    <p>Again with this one I have no idea what to call it but I will attempt to explain it the best I can.</p> <p>I created a question similar to this before that did get answered but only because I wasn't 100% sure what I was looking for. Now I have worked out what I need etc.. </p> <p>So I have created this example, you will see that there are multiple inputs but they only work in the first column (due to no knowing how to make the others work). So now I need to get that working in ALL other columns using the same functions.</p> <p><a href="http://jsfiddle.net/Ruddy/J4ALs/" rel="nofollow noreferrer"><strong>EXAMPLE</strong></a></p> <h2>HTML:</h2> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;th&gt;&lt;/th&gt; &lt;th&gt;Option1&lt;/th&gt; &lt;th&gt;Option2&lt;/th&gt; &lt;th&gt;Option3&lt;/th&gt; &lt;th&gt;Option4&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Money&lt;/td&gt; &lt;td&gt;&lt;input type="number" id="money" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Upfront&lt;/td&gt; &lt;td&gt;&lt;input type="number" id="upfront" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Overall Price&lt;/td&gt; &lt;td id="overallPrice"&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Discount&lt;/td&gt; &lt;td&gt;&lt;input type="number" id="discount" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="number" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Dicount Price&lt;/td&gt; &lt;td id="discountPrice"&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <h2>Javascript/jQuery:</h2> <pre><code>$(document).ready(function () { $('input').keyup(function () { overallPrice(); discountPrice(); }); }); function overallPrice() { var cal1, cal2, result; cal1 = parseFloat(document.getElementById("money").value); cal2 = parseFloat(document.getElementById("upfront").value); result = cal1 - cal2; document.getElementById("overallPrice").innerHTML = "£" + result; return result; } function discountPrice() { var cal1, cal2, result; cal1 = parseFloat(document.getElementById("discount").value); cal2 = overallPrice(); result = cal2 - cal1; document.getElementById("discountPrice").innerHTML = "£" + result; } </code></pre> <p>So we have 2 inputs that will create the "Overall Price" and then the 3rd input will take that number and give the "Discount Price". If this was just 1 single column I could do it no problem but as I need this to work for all of the columns I'm not sure how I can do this using the same functions.</p> <p>Hope this made some sort of sense if not let me know and I will try explain some more.</p> <p>Here is a link to my other question, I added this part onto the end of it just encase you want to see where I started etc. </p> <p><a href="https://stackoverflow.com/questions/20700435/multiple-calculations-display-on-same-page"><strong>Other Question</strong></a></p> <p>*Note: There will be more then 2 sets of inputs, this is just an example. In my real version some of the inputs will not be used for certain columns and I will have to change some function to calculate certain columns differently. *</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.
 

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