/    Sign up×
Community /Pin to ProfileBookmark

replicating fields

Hi,
I need some help with creating a survey form that has a question area(textbox) and an answer area(textarea) and a button with a “+” symbol. when a user clicks on the “+” button the question and answer areas need to be replicated (i.e., if the first q/a pair exists another q/a areas should be added)and so on…
Any suggestions/help in regard to this problem is appreciated.

Thanks…

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJul 22.2003 — This is how you can get this done.

in the onclick event of the button call a function say

onclick="Replicate();"

now in the JavaScript section of the code define this function something like this

function Replicate(){

//get reference to the form that has the fields

var frm = document.getElementById("formId");

//now create new fields to be appended

var newtextField = document.createElement("input");

//now set this type to text

newtextField.setAttribute("type","text");

//you can add many attributes just like above such as id,name,value...etc

//now just append the above new form field to the existing form

frm.appendChild(newtextField);

//there you go...

}
Copy linkTweet thisAlerts:
@sdevauthorJul 22.2003 — Thanks Khalid.....

the piece of code u gave me is really helpful.
Copy linkTweet thisAlerts:
@Khalid_AliJul 22.2003 — ?

You are welcome
Copy linkTweet thisAlerts:
@sdevauthorJul 22.2003 — i had another question to ask :

with the code that is replicating the q/a areas , the text boxes are placed next to each other , though i'm trying to give the <br> tag with document.write("<br>"), so that they come one after another , the above tag doesn't seem to work.

Any suggestions...


Thanx
Copy linkTweet thisAlerts:
@Khalid_AliJul 22.2003 — What you'd need to do is create another element just the way I showed you above only this time it will be

document.createElement("br");

and append it to the form element after the text field the order will be this

form.appendChild("textField");

form.appendChild("br_element");
Copy linkTweet thisAlerts:
@sdevauthorJul 22.2003 — Awesome.....thanks
Copy linkTweet thisAlerts:
@Khalid_AliJul 22.2003 — ? My Pleasure SDev ?
×

Success!

Help @sdev 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 5.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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