I'm trying to learn JavaScript and trying to calculate the average of sulfur and carbon in user input text
P粉323374878
2023-09-03 14:05:56
Please refer to the HTML table below to understand the question.
I've created a table and I've numbered my text boxes for clarity. I'm trying to calculate the average of text input 1 (% sulfur) and text input 2 (% sulfur) and display the result in a read-only text input 5 (average sulfur). This is for sulfur.
I'm also trying to calculate the average of text input 3 (% carbon) and text input 4 (% carbon) and display the results in a read-only text input 6 (average carbon). This is for carbon.
Additionally, I would like the JavaScript to do this repeatedly, averaging the next text inputs in the table (input7 and input8) and display the result in read-only input 11.
The formula should also do the same for inputs 9 and 10, displaying the result in read-only input 12
If you take the
dataset
attribute, you can associate input and output elements in such a way that calculations can be performed with any number of inputs. The comments in the javascript below should explain what's going onI know you are new to JavaScript, so much of what you see here may be very intimidating and confusing. Still, as your knowledge grows, you'll hopefully find value in some of the techniques presented here - but if you have questions, feel free to ask!