Get input ids using for no js

Asked

Viewed 17 times

0

Hello, I’m trying to take the value of 10 inputs and put them in a vector of 10 houses, but I’m not able to do it for the sake of, can someone help me to get no off var n[0] for example take the value of inputVetor0?

var i;
function calcularMaior() {
    var n = new Array(10);
    for(i = 0; i < 10; i++) {
        var input = "input";
        var inputNumero = "" + i.toString();
        var inputId = input.concat(inputNumero);
        n[i] = document.getElementById(inputId).innerHTML;
    }
    alert("Array 0 = " + n[0];
}

Complete code: https://jsfiddle.net/sf14tf8c/

1 answer

1


You’re trying to catch the innerHTML of the inputs when should take the value:

n[i] = document.getElementById(inputId).value;
  • thanks bro, I’m very new still, I had based on a similar problem and adapted, so I didn’t understand what was to do, really worth.

  • Tip: innerHTML is what stands between <tag> and </tag>. Notice that inputs have no closing tag. With inputs and selects you should always use value to obtain the current value.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.