Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple reusable javascript averaging function for multiple forms on same page
    primarykey
    data
    text
    <p>I literally started trying to teach myself javascript less than 48 hours ago. Outside of just wanting to learn it I also have a small personal project I'm working on and using as sort of my working learn as I go example. But I've hit a problem, which I'm sure is rather basic, I'm just hampered by lack of much javascript knowledge. </p> <p>Basically it is just an averaging problem.<br> There are going to be 4 inputs fields with the 4th being a rounded to the nearest whole number average of the first three fields.<br> This 4 field configuration is going to get used multiple times on the page.<br> I want it to work in "real time" and not with a calculate button so I'm assuming "<strong>onKeyup</strong>" is needed. (no validation of any kind is needed or submit or saving or anything)</p> <p>The only code I've been able to get close is really really ugly, long, and convoluted. I can't help but think there is a very simple way to do it and just get the same function to apply to each grouping of inputs. It will look like below but probably much longer.</p> <pre><code>some text &lt;input id="a" type="number" /&gt;&lt;br/&gt; &lt;input id="b" type="number" /&gt;&lt;br/&gt; &lt;input id="c" type="number" /&gt;&lt;br/&gt; &lt;input id="final" value="0" disabled /&gt; some text &lt;input id="a" type="number" /&gt;&lt;br/&gt; &lt;input id="b" type="number" /&gt;&lt;br/&gt; &lt;input id="c" type="number" /&gt;&lt;br/&gt; &lt;input id="final" value="0" disabled /&gt; </code></pre> <p>Thanks in advance. This is part of a larger problem but I've tried to strip it down to it's essence and seeing it work and understanding it will go a long way to helping me solve some other problems. </p>
    singulars
    1. This table or related slice is empty.
    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