code extracted from commonform.js