سؤال

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?

هل كانت مفيدة؟

المحلول

<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;
}

نصائح أخرى

I was having a trouble using this function to add 'tr'.

The code that I used was..

 function Start($oid){
   $objResponse = new xajaxResponse();
   $userauth = Authorizer::getUserByID($oid); // I Save here DB rows return.
      while ( $rows = $userauth->fetchRow() ){
          $row[] = $rows['uid'];

        $userInfo = User::userInfo($rows['uid']);
   $useradd .= '              <tr class="spaceunder">
                                 <td>'. $rows['uid'] .'</td>
                                 <td>'. $rows['status'] .'</td>
                                 <td>'. $rows['perm'] .'</td>
                                 <td>'. $rows['dtauth'] .'</td>    
                              </tr>';

        $objResponse->addAlert($useradd);
        $objResponse->addAssign('userAdded', 'innerHTML', $useradd);

         return $objResponse->getXML();
     }

And my HTML is...

    <table id ="userAdded" border="0" cellpadding="0" cellspacing="0" style="width:100%;height:100%;padding:5px 0px 0 0px;margin:0px 0px 0 0px;">
                <tr valign="top" style="height:37px;padding:1px 1px 1 1px;margin:0px 0px 0 0px;"> 
                   <td align="left">
                      <table width="100%" cellspacing="0" cellpadding="0" border="0">



                      </table>
                   </td>
                </tr>
            </table>'

And it works perfectly.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top