0

I want to access values of below elments

opener.document.EditView.flight_no1_c.value
opener.document.EditView.flight_no2_c.value
opener.document.EditView.flight_no3_c.value
opener.document.EditView.flight_no4_c.value

Here only numbers are changing ranging from 1 to 4. How can I make this into loop.

user2864740
  • 60,010
  • 15
  • 145
  • 220
user3286692
  • 383
  • 1
  • 5
  • 23

2 Answers2

2

You can use for loop and call properly using [] insteand on ., see below code

for(var i = 1; i <= 4; i++ ){
  opener.document.EditView["flight_no"+i+"_c"].value
}
Girish
  • 11,907
  • 3
  • 34
  • 51
0

what about

for(var key in opener.document.EditView){
    if(key.match(/^flight_no\d+_c/)){
       console.log(key.value);
    }
}
Haim Raman
  • 11,508
  • 6
  • 44
  • 70