html-tablerowxajax

Append row in table using XAJAX - values are deleted


I have this table in HTML:

<table style="width: 100%;" class="allBorders">
    <tbody id="added_articles">
        <tr id="header_articles">
            <td>test</td>
            <td>&nbsp;</td>
        </tr>
    </tbody>
</table>

And using XAJAX I append new ROW like THIS

function addNewLine()
{
    global $objResponse;
    $uniqueID = time();
    $return = "<tr id='articles_".$uniqueID."'>";
    $return .= "<td><input type='text' id='v_$uniqueID' name='v[]' /></td>";
    $return .= "</tr>";
    $objResponse->append("added_articles", "innerHTML", $return);
    return $objResponse;
}

Whenever I add new line all values in previously added lines are cleared..

Example:

  1. 1st line is added
  2. value in 1st line is set to "TEST"
  3. 2nd line is added and value in 1st line is deleted .. .

Any idea?


Solution

  • <div id="added_articles">
        <table style="width: 100%;" class="allBorders">
            <tbody>
                <tr id="header_articles">
                    <td>test</td>
                    <td>&nbsp;</td>`enter code here`
                </tr>
            </tbody>
        </table>
    </div>
    
    function addNewLine()
    {
        global $objResponse;
        $return .= "<table style="width: 100%;" class="allBorders">";
        $return .= "<tr id='articles_".$uniqueID."'>";
            $return .= "<td><input type='text' id='v_$uniqueID' name='v[]' /></td>";
        $return .= "</tr></table>";
        $objResponse->append("added_articles", "innerHTML", $return);
            return $objResponse;
    }