Skip to main content
Known Participant
October 27, 2008
Question

Adding new rows

  • October 27, 2008
  • 1 reply
  • 377 views
I found some javascript code that will add extra rows when a button is clicked, and delete exisitng rows with anohter button. Everything works fine, but I have two questions.

The first line I create in html, using <td align="center">. The javascript dose not seem to allow that, so the next row is out of alignment and I have to use   to align/center with the first row. I tried to modify the javascript to add the align, but it will not work and blows up. How do I modifiy the javascript code so that the next line created aligns with the first line ?

The second question is how do I modify the javscrpt code to validate that each of fields created in the next row are requried for entry ?

Thanks for any help.
    This topic has been closed for replies.

    1 reply

    October 29, 2008
    Can you post your comment so that we can reply sensibly?
    Known Participant
    October 30, 2008
    This is the javascript code that I am using. I added the multiple   to align each additional row with my first row. Is there a better way to do this ? Also, how can I edit (required entry) each of the fields in the additonal rows ?

    <script type="text/javascript">
    function addMaterialNumbers() {
    //add a row to the rows collection and get a reference to the newly added row
    var newRow = document.all("addMaterialNumbers").insertRow();

    //add 3 cells (<td class="TitleText" >) to the new row and set the innerHTML to contain text boxes

    var oCell = newRow.insertCell();
    oCell.innerHTML = "       <input type='text' name='conditionCode' size='4'>";

    oCell = newRow.insertCell();
    oCell.innerHTML = "        <input type='text' name='materialNumber' size='20'>";

    oCell = newRow.insertCell();
    oCell.innerHTML = "    <input type='text' name='quantity' size='8' value='0'>";

    oCell = newRow.insertCell();
    oCell.innerHTML = "    <input type='text' name='unitValue' size='8' value='0.00'>";

    oCell = newRow.insertCell();
    oCell.innerHTML = "     <input type='text' name='snFlag' size='1'>"

    oCell = newRow.insertCell();
    oCell.innerHTML = "   <input type='button' value='Delete' onclick='removeRow(this);'/>";

    }

    //deletes the specified row from the table
    function removeRow(src)
    {
    /* src refers to the input button that was clicked.
    to get a reference to the containing <tr> element,
    get the parent of the parent (in this case <tr>)
    */
    var oRow = src.parentElement.parentElement;

    //once the row reference is obtained, delete it passing in its rowIndex
    document.all("addMaterialNumbers").deleteRow(oRow.rowIndex);

    }
    // -->
    </SCRIPT>
    Known Participant
    November 3, 2008
    Help. Does anyone know how to do this ? My script adds and deletes rows and works fine. I just need to know how to validate each cell in the new row(s), to make it a required entry and display a popup error message.