Topic: Appending table row - previous values are deleted

Hi,

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:
- 1st line is added
- value in 1st line is set to "TEST"
- 2nd line is added and value in 1st line is deleted .. .

Any idea?

Regards

Re: Appending table row - previous values are deleted

Hi,

I made up this code:

<?php
include 'xajax/xajax_core/xajax.inc.php';
$xajax = new xajax();
$xajax->configure('javascript URI','xajax/');
function addNewLine()
{
    $objResponse=new xajaxResponse();
    $uniqueID = time();
    $return = "<tr id='articles_".$uniqueID."'>";
    $return .= "<td><input type='text' id='v_$uniqueID' name='v[]' value='v_$uniqueID'/></td><td>&nbsp;</td>";
    $return .= "</tr>";
    $objResponse->append("added_articles", "innerHTML", $return);
    return $objResponse;
}
$xajax->register(XAJAX_FUNCTION, 'addNewLine');
$xajax->processRequest();
?>
<!DOCTYPE html>
<html>
<title>Test table row add</title>
<head>
<?php $xajax->printJavascript() ?>
</head>
<body>
<table style="width: 100%;" border="1">
<tbody id="added_articles">
<tr id="header_articles">
<td>test</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<br/>
<input type="button" value="Add Row" onclick="xajax_addNewLine()"/>
</body>
</html>

Tested it with Chrome and FF and it works as it should.

I'm using xajax 0.5 and php 5.3.13

Let me know if you still need help.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

3 (edited by mazi 2013-02-07 2:12:32 PM)

Re: Appending table row - previous values are deleted

When editing tables with ajax remember taht it only works in FF and chrome. it won't work in IE, bc. strictly it is not allowed to simply append/insert rows.
If you want it to work you will have to use the xajax-plugin "tableupdater" which uses DOM, or better: create your tables not with the html table tag but with the CSS3 table styles where you can turn your divs/spans into tables/rows/columns.