for (var s in wid){ var percent = Math.round((wid[s].value*100)/40); for (var i =0;i < elems.length;i++) { elems[i].setAttribute('style', 'width:' + percent + '%'); } }