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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:02:18+00:00 2026-06-10T15:02:18+00:00

Hello im trying to generate dynamic divs with a textbox and delete button in

  • 0

Hello im trying to generate dynamic divs with a textbox and delete button in it. On form submit i want all dynamically generated textboxes values, how can i assign unique id to the textbox element. The ID’s / Name of textbox should be unique.. to get all values properly.
Pls suggest..

My Code:

<HTML>
<HEAD>
<TITLE> Add/Remove dynamic elements</TITLE>
<SCRIPT language="javascript">
    function addRow(divId) {
        count = 0;
        count++;

        var parentDiv = document.getElementById(divId);

        // create a div dynamically
        var eleDiv = document.createElement("div");
        eleDiv.setAttribute("name", "olddiv");
        eleDiv.setAttribute("id", "olddiv");

         // create a textbox dynamically
        var eleText = document.createElement("input");
        eleText.setAttribute("type", "text");
        eleText.setAttribute("name", 'textbox' + count);
        eleText.setAttribute("id", "textbox");

        // create a delete button dynamically
        var eleBtn = document.createElement("input");
        eleBtn.setAttribute("type", "button");
        eleBtn.setAttribute("value", "delete");
        eleBtn.setAttribute("name", "button");
        eleBtn.setAttribute("id", "button");
        eleBtn.setAttribute("onclick", "deleteRow('button')");

        // append new div to parent div 
        parentDiv.appendChild(eleDiv);

        // append textbox & button to new div 
        eleDiv.appendChild(eleText);
        eleDiv.appendChild(eleBtn);

    }

    function deleteRow(tableID) {
            var div = document.getElementById('olddiv');
            if (div) {
                div.parentNode.removeChild(div);
            }
    }

</SCRIPT>

<form name="objForm" action="test1.php">
    <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
    <div id="dataTable" width="350px"><INPUT type="text" name="txtData" /></div>
    <input  type="submit" value="Submit"/>
</form>

  • 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-10T15:02:20+00:00Added an answer on June 10, 2026 at 3:02 pm

    To answer your question directly you could try:

    var textboxCount = 0;
    
    /* In your function */
    // create a textbox dynamically
    var eleText = document.createElement("input");
    eleText.setAttribute("type", "text");
    eleText.setAttribute("name", 'textbox' + count);
    eleText.setAttribute("id", "textbox" + textboxCount);
    textboxCount += 1; //Increment the count
    

    That will create textbox’s with id’s textbox0, textbox1, textbox2 etc.

    Or, for a more efficient option you may store all textboxs you create in an array, like so:

    var textboxes = new Array();
    
    /* In your function */
    // create a textbox dynamically
    var eleText = document.createElement("input");
    eleText.setAttribute("type", "text");
    eleText.setAttribute("name", 'textbox' + count);
    
    textboxes.push(eleText);
    

    Now instead of calling e = document.getElementById('textbox4'); you may call e = textboxes[4];

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

Sidebar

Related Questions

Hello I'm trying to dynamically generate some inputs for my form, but it's not
Hello i was trying to modify an object form the values of another object
I am trying to invoke an internal method from a dynamically generated one. The
Hello I am trying to generate a Drupal node which would be similar to
Hello Im trying to get all possible combinations with repetitions of given char array.
Hello and thanks in advance for the help! I am trying to generate a
I am trying to generate some XML on-the-fly in Scala. I want to use
Hello I've been trying for couple of days to write a script to generate
Hello everyone I'm trying to convert a PKCS#8 private key that I generate in
Hello there I am trying to execute the .exe file generated by the below

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.