Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6095081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:46:22+00:00 2026-05-23T12:46:22+00:00

This page allows users to add questions dynamically (this part works), within each question

  • 0

This page allows users to add questions dynamically (this part works), within each question a user can add one to many answers which are also dynamic. Here’s a wire frame of the page which might help: https://gomockingbird.com/mockingbird/#2ql43kg/0W2gD1

As I said, the question part is done and the fields are being posted from the form correctly.

I need some help thinking through how to go about adding the answer area. Here is my code thus far.

<script>
currentQuestion = 1;

 function addQuestion(){
// Clone our question container and assign it a new ID
var newElement = $('#questionContainer0').clone().attr('id','questionContainer'+currentQuestion);
// Update the ID and Name of the textarea in our question container
newElement.children('#question0').attr('id','question'+currentQuestion).attr('name','question'+currentQuestion);
// Append our new question container to the bottom
newElement.appendTo('#questionArea');

currentQuestion++;
}

function addAnswer(){
//var newAnswer = $('#question0-answer1').clone().attr('id','question0-answer2').attr('name','question0-answer2');
//newAnswer.appendTo('#answerContainer0');
}
</script>
</head>

<form method="post" action="test.cfm">
<div id="questionArea">
<div id="questionContainer0" class="questionContainer">
    <textarea id="question0" name="question0"></textarea>
    <div id="answerContainer0">
    <input type="text" id="question0-answer1" name="question0-answer1" />
    <p><a href="#" onClick="addAnswer();" id="add">Add Answer</a></p>
</div>  
</div>

<input type="submit" value="go" name="submit">
</form>
<a href="#" onClick="addQuestion();" id="addQuestion" title="Add a question" class="link-sm" style="background-color:red;">Add Question</a>

FWIF, I am new to JQuery and if how I am approaching this is wrong entirely, please let me know 🙂 – I am sure there is a slicker way to do it without writing an addQuestion function and calling it with an onClick.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:46:22+00:00Added an answer on May 23, 2026 at 12:46 pm

    I’d do it this way:
    First, change your addAnswer link html to the following:

    <a href="javascript:" class="add-answer">Add Answer</a>
    

    Your script would be this:

    $(document).ready(function(){
       $(".add-answer").click(function(){ //bind a click event
           addAnswer($(this));
       });
    });
    
    function addAnswer($anchor){
      var questionId = $anchor.siblings("textarea").attr("id");
      var answerIndex = $anchor.siblings(":text").size() + 1;
      var answerId = questionId + "-answer" + answerIndex;
      var $lastAnswer = $anchor.siblings(":text:last");
      $lastAnswer.clone().attr("id", answerId).attr("name", answerId).insertAfter($lastAnswer); //Changed this line
    }
    

    And I’d remove the currentQuestion global var and change the addQuertion function also:

    function addQuestion(){
      var curentQuestion = $(".questionContainer").size(); //Number of questionContainers
      var $newElement = $('#questionContainer0').clone().attr('id','questionContainer'+currentQuestion);
      $newElement.children('#question0'). attr('id','question'+currentQuestion).attr('name','question'+currentQuestion);
      //Update the answerContainer div id.
      $newElement.children('#answerContainer0') .attr('id','answerContainer'+currentQuestion);
      //Update the first answer id and name
      var answerId = 'question'+currentQuestion+'-answer1';
      $newElement.children('#question0-answer1').attr('id',answerId).attr('name',answerId);
      $newElement.appendTo('#questionArea');
    }
    

    And that’s it. If you have doubts, just ask me.
    Hope this helps. cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This page from Adobe says to add a wmode parameter and set its value
I currently have a page that allows a user to enter different types of
I use one WYSIWYG editor in a small cms. It allows users to upload
This page mentions how to trunc a timestamp to minutes/hours/etc. in Oracle. How would
This page displays beautifully in firefox but i get all kinds of problems when
On this page in the Subversion manual , it says that When you commit
I found this page describing the Muenchian method, but I think I'm applying it
According to this page, it's possible to use TClientDataset as an in-memory dataset, completely
If you visit this page in Internet explorer, and choose a value from the
I have an ASPX page and on this page I have a control that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.