Mubashar Ahmad Mubashar Ahmad - 3 months ago 40
Javascript Question

Auto increment value in element id

I am trying to get value of dynamic generated inputs. Here is my code and what I want actually

Here is my Code:

function activehead_standard(){
var cnt = 4;
for(i=1;i<=cnt;i++){
var active_head = document.getElementById('standard_'.i).value;

}

}


I want to get values of input:
standard_1
standard_2
standard_3
standard_4

but its not getting the value of input through ids I am sure its actually not getting the ids of inputs

Answer

use + for concatenation in javascript

function activehead_standard(){
var cnt = 4;
for(i=1;i<=cnt;i++){
var active_head = document.getElementById('standard_'+i).value;

}

}