/    Sign up×
Community /Pin to ProfileBookmark

setting value of similar named form fields

If a user checks a checkbox, I want to prefill form field data. I don’t want to use eval() but the below code causes ‘Cannot read property ‘1’ of undefined’. All the field names end in a number (1 through 10).
for (var checkbox of checkboxes) {
if (memberCount === 11) {
break;
}
prefillData = checkbox.value.split(“,”);
myForm.bass[memberCount].value = prefillData[2];
myForm.bassexp[memberCount].value = prefillData[3];
myForm.firstname[memberCount].value = prefillData[1];
myForm.lastname[memberCount].value = prefillData[0];
myForm.phone[memberCount].value = prefillData[4];
myForm.email[memberCount].value = prefillData[5];
memberCount++;
}

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @mickeyg spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...