/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] clicking button to add multiple input fields.

Hi, guys.

I’m trying to add a row of fields like the following when I press a button.

name[] height[] age[]
name[] height[] age[]
name[] height[] age[]

I need that [] bracket to process the values in an array for PHP later.

So, obviously I could createElement for each one and append them, but I wanted to use a loop for efficiency and for later expendability. But for some reason, nothing happens when I press the button. Is there something that I’m missing?

[CODE] function addform() {
var defaultName = new array(“name”, “height”, “age”);
var formName = new array(“nameForm”, “heightForm”, “ageForm”);
var count=defaultName.length
var i=0
for (i=0; i<=count; i++) {
formName[i] = document.createElement(“input”);
formName[i].type = “text”;
formName[i].name = defaultName[i] + “[]”;
inHere = document.getElementById(“inhere”);
inHere.appendChild(formName[i]);
}
}[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@voidvectorDec 09.2008 — "Array" in "new Array" should be upper case. And your for loop should probably have "i<count" instead of "i<=count".
×

Success!

Help @rubenhan 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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