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 8470035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:24:01+00:00 2026-06-10T16:24:01+00:00

So as the title says I’m trying to add input tags to a form

  • 0

So as the title says I’m trying to add input tags to a form I have based on a dropdown selection. This is what I have so far:

HTML FORM:

<form action="/next" method="POST" > 
    <select name="category" id="category" onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
    </select>
    <div id="count">
        <p>
            <div id="something">
                <input type="text" name="text" value="" >
                <input type="text" name="othertext" value="" >
            </div>
        </p>
        <span id="Room"></span>
    </div>
    <input type="submit" value="Next" >
</form>

And then the Javascript that is doing what I want:

function dropdownlist(listindex) {

    document.Room = 0;
    switch (listindex) {

    case "1":

        var check = document.getElementById('added');
        if (check != null) {

            element = document.getElementById('added');
            element.parentNode.removeChild(element);

            element = document.getElementById('added');
            element.parentNode.removeChild(element);

            element = document.getElementById('added');
            element.parentNode.removeChild(element);


        }

        break;

    case "2":


        var check = document.getElementById('added');
        if (check == null) {

            var counter = 1;

            var newFields = document.getElementById('something').cloneNode(true);
            newFields.id = 'added';
            var newField = newFields.childNodes;
            for (var i = 0; i < newField.length; i++) {

                var theName = newField[i].name
                if (theName) newField[i].name = theName + counter;
            }
            var insertHere = document.getElementById('Room');
            insertHere.parentNode.insertBefore(newFields, insertHere);

        }

        else {
            var id = document.getElementById('count');
            var countid = id.getElementsByTagName('p')
            var number = countid.length;

            if (number == 3) {
                element = document.getElementById('added');
                element.parentNode.removeChild(element);
            }​

    }​

Now this is all working quite nicely, there might be better ways of doing this but as I really have little experience with javascript it’s been the best I’ve managed to do. Now the problem is this: If a user added 3 elements and then decided to actually go back to 2, I had to run a check on how many tags where added, the solution I came up with required me to add a < p> tag around each element created on top of a div so I could select all the < p> tags within the div and then delete the required amount of tags.

This solution was good but then I noticed that this messed up with an earlier part of my code where I changed the name of each input tag to something unique, which is something I need to store the information in the form.

So can anyone suggest me a different workaround to achieve this functionality? add and delete input tags based on user selection while keeping unique names for all tags? Any help at all would be greatly appreciated!

  • 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-06-10T16:24:02+00:00Added an answer on June 10, 2026 at 4:24 pm

    Is your maximum number of input elements small? If so, you might consider incorporating all of them on the page up front, and then enabling them or setting their visibility as needed:

    document.form1.text1.disabled = true;              // or false
    
    document.form1.text1.style.visibility = "hidden";  // or "visible"
    

    This requires first naming your form and your input elements:

    <form name="form1" ... >
    
    <input type="text" name="text1" ... >
    <input type="text" name="text2" ... >
    

    This approach is much simpler than manipulating the DOM via insertBefore(),removeChild(), etc.

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

Sidebar

Related Questions

As the title says, I'm trying to do something like this: public abstract class
As the title says, i am trying to find the customer's who have made
Title says all. I'll have navigation that looks like this and it's dynamically created
As title says, I have a list of words, Like stopWords = [the, and,
As title says, I have access to the current listitem - and it's easy
The title says it mostly. If I have an object in Python and want
The title says enough I think. I have a full quality BufferedImage and I
As title says, is there a way to send form when element outside of
As title says, is there any way to pull something like this up?: std::set<boost::shared_ptr<MyClass>>
The title says it: I have an excel Sheet with an column full of

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.