javascript - Use i in var name on a for cicle -


this not working have no idea how correct it:

for(i=1; i<=3; i++){     var address_con+[i] = document.getelementbyid("address_con[i]")     var cap_con+[i] = document.getelementbyid("cap_con[i]")     var city_con+[i] = document.getelementbyid("city_con[i]") } 

it should produce:

//first element address_con1 = document.getelementbyid("address_con1") etc. //last element city_con3 = document.getelementbyid("city_con3") 

the error on:

var name+[i] 

thank you

there no replacement of variables inside strings in javascript (unlike in php, possible). similar creating new variables, can't in way, trying.

to naming, can use following code, store values inside result variable.

var result = {}; for(var i=1; i<=3; i++){     result[ "address_con" + ] = document.getelementbyid("address_con" + i)     result[ "cap_con" + ] = document.getelementbyid("cap_con" + i)     result[ "city_con" + ] = document.getelementbyid("city_con" + i) } 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

java - How to create Table using Apache PDFBox -

c# - Attempting to upload to FTP: System.Net.WebException: System error -