Fix JS bug for preselecting elements