Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
JavaScript Clear TextBox on Clone Node

Looking for suggestions on how to clear the textbox(es) when an HTML form is cleared. Here is the JS code that is run onclick:

 var counter = 0;
    function moreField() {
        counter++;
        var newFields = document.getElementById('readroot').cloneNode(true);
        newFields.id = '';
        newFields.style.display = 'block';
        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('writeroot');
        insertHere.parentNode.insertBefore(newFields, insertHere);
    }

I have tried doing a getelementbyId and trying to assign the newly created textbox a value of "" but that did not seem to work. Here is the HTML code that creates the form that is cloned:

<div class="InfoPanel">
            <div id="readroot" style="display: block">
                <br />
                    <asp:TextBox ID="txtHeadline" Columns="70"  MaxLength="200" runat="server" />
                    <textarea id="txtReview" rows="5" cols="70" name="review"></textarea>           
                <br />
<input type="button" value="[Delete]" id="btnDeleteDetail" style="display: block; margin:auto; text-decoration:underline; text-align: right; border:none; cursor:pointer; color:#412C82; "  onclick="this.parentNode.parentNode.removeChild(this.parentNode);" />
            </div>
            <form method="post" action="#">
                <div id="writeroot"></div>
            </form>
                <asp:Button ID="btnAddDetail" autopostback="false" Text="Add Detail" CssClass="formbutt" OnClientClick="moreField();return false;" runat="server" />
            <br />
        </div>

As it currently sits, running this code duplicates the form just fine but any text entered into the first form will be included in any subsequent forms. Thanks for the help in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

    <div id="readroot" style="display: block">

Should have been display: none which provides a clean slate on clone.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!