I've already implemented this, but as I'm not familiar with the FOR loop statement I've done it this way as shown below! Can you please help me shorten this code using the FOR loop statement and explain me how this works! Thanks
Here is my code:
var inputs = new Array();
inputs["a"] = document.getElementById("a").value;
inputs["b"] = document.getElementById("b").value;
inputs["c"] = document.getElementById("c").value;
inputs["d"] = document.getElementById("d").value;
inputs["e"] = document.getElementById("e").value;
And then I've added them up as:
var inputsvalue = inputs["a"] + inputs["b"] + inputs["c"] + inputs["d"] + inputs["e"];
Note that I'm adding the value of each input field and assigning them into a variable!
For example lets say the values for input fields a, b, c, d, e are as follows:
1, 2, 3, 4, 5
So I want them to be assigned to the variable "inputsvalue" like:
var inputsvalue = "12345";
That's why I added them like that! So is there any other way to do this! In this example I only have 5 input fields, but what if there was about 100 input fields!
The purpose of this question is to learn how FOR loop statement works in this example!
Thanks in advance! :)
"12345"part would be to just dovar inputsvalue = inputs.join('');