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

  • SEARCH
  • Home
  • 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 952007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:49:30+00:00 2026-05-15T23:49:30+00:00

I am trying to have a form of text inputs. All inputs will in

  • 0

I am trying to have a form of text inputs. All inputs will in an ordered list OL/LI structure.
There will be a + symbol next to the input that when you click on it, it should create a sub-OL and make a secondary list with another input. If you click it again, it adds another input. The new inputs have + symbols as well and you can do the same thing. I only technically want it to go three deep, but I think I can figure that part out later on, but what I’m really after is how to make this happen.

I have a beginning phase of it, but it’s duplicating too much of the LI and I’m not sure what’s going on.
This is what I have.

    $('.add_sub_page').live('click',function(e){
    $("<ol>").append($(this).parent().clone()).insertAfter(this);
    e.preventDefault();
});

I brought this up an IRC chat room and I was provided with this solution, but it has the same issue as my first solution, so I’m not sure if it’s easier to work with or not, so I will provide it as well.

    $('.add_sub_page').live('click',function(e){
    var ol = $("ol",this), new_ol = ol.length ? false : true;

    ol = new_ol ? $("<ol>") : ol;

    ol.append($(this).parent().clone());

    if (new_ol) {
        ol.insertAfter(this);
    }

    e.preventDefault();
});

And just so you can see what HTML I am working with…

<form id="sitemap" action="" method="post">
<ol>
    <li class="page-title"><label>Page Name: </label><input type="text" name="pages[]" value=""><a class="add_sub_page">+</a></li>
    <li class="page-title"><label>Page Name: </label><input type="text" name="pages[]" value=""><a class="add_sub_page">+</a></li>
    <li class="page-title"><label>Page Name: </label><input type="text" name="pages[]" value=""><a class="add_sub_page">+</a></li>
    <li class="page-title"><label>Page Name: </label><input type="text" name="pages[]" value=""><a class="add_sub_page">+</a></li>
    <li class="page-title"><label>Page Name: </label><input type="text" name="pages[]" value=""><a class="add_sub_page">+</a></li>
</ol>
<p><input type="submit" name="submit_step1" value="Next Step"></p>
</form>

You can preview the issue at http://jsbin.com/everu3 — click the same Plus (+) sign twice to see the issue.

Thanks for any help you can provide!

  • 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-15T23:49:31+00:00Added an answer on May 15, 2026 at 11:49 pm

    You just need to remove those child <ol> elements you added earlier when appending, like this:

    $('.add_sub_page').live('click',function(e){
      $("<ol>").append($(this).parent().clone().children('ol').remove().end())
               .insertAfter(this);
      e.preventDefault();
    });​
    

    You can give it a try here, all we’re doing different is when you’re cloning it looks for .children() that are <ol> elements, perform a .remove() on them from the cloned set and use .end() to hop back up the chain to the original cloned element, since that’s the one you want to append.


    Edit: The original version created an <ol> per, to get the current numbering, we need one <ol> beside the <a> we’re clicking. To do that change it up a bit like this:

    $('.add_sub_page').live('click',function(e){
      $(this).parent(':not(:has(ol))').append('<ol></ol>');
      $(this).next().append($(this).parent().clone().children('ol').remove().end());
      e.preventDefault();
    });​
    

    Give it a try here. What this does is it goes to the parent, only if it doesn’t have a <ol> and appends an <ol> (if it already has one the .append() wouldn’t run in anything). Then we’re just looking for that <ol> which should be the .next() element and appending to it.

    Also here’s a slightly modified version that stops at 3 levels:

    $('.add_sub_page').live('click',function(e){
      $(this).parent(':not(:has(ol))').append('<ol></ol>').end()
             .next().append($(this).parent().clone().children('ol').remove().end());
      if($(this).parents('.page-title').length == 2)
         $(this).next().find('.add_sub_page').remove();
      e.preventDefault();
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a form that will have mixed inputs mostly text and
I have a form that is trying to insert some data into an SQL
I have a WPF form where I'm trying to make a simple input form.
Please have a look at this form that I am trying to design with
I'm trying to write some JavaScript for my website that will select all the
I'm trying to create a simple login system that will have the forms and
I am trying to write data from form inputs to a text file using
I'm trying to use jquery to set some default text in a form input.
This is what I'm trying to do. Have one main form with all the
I'm trying to have the owner-form minimize when the modal-form is minimized. But when

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.