doujiling4377 2016-02-11 19:00
浏览 51

无法通过其ID获取表单

I have a form that created in an external file and then i'm including it by php and then getting this form by its id to serialize. index.php

<div id="addressesList">        
 <?php include 'addresstable.php' ?>
</div>

view source of index.php file: enter image description here

jquery code in index.php:

<script>
   function editAddress(){
       $.ajax({
        url: 'insert.php',
        type: 'POST',
        data: $('#addressListForm').serialize() , // An object with the key 'submit' and value 'true; + '&' + 'editAddress' + '=' + id
        success: function (result) {
          //$(thisObj).parents("tr:first").remove();

          $("#addressesList").html(result);
        }
    }); 
   }
</script>

I want to get the form that its id is "addressListForm" by click on an element that calls editAdress function. addresstable.php file

                <?php
                    $i=1;
                    $results=mysqli_query($dbCnn,"select * from addresses");
                    while( $row=mysqli_fetch_array($results,MYSQLI_ASSOC))

                    { 
                        echo '<form action="insert.php" method="post" id="addressListForm">';
                        echo "<tr>
                                <input type='hidden' value='$row[id]' name='id'/> 
                                <td>$i</td>
                                <td><input name='title' type='text' value='$row[title]' style='width:60px'  /></td>
                                <td><input name='address' type='text' value='$row[address]' style='width:100%' /></td>
                                <td><input name='tel' type='text' value='$row[phone]' required='required' style='width:100px' /></td> 
                                <td><input name='fax' type='text' value='$row[fax]' required='required' style='width:100px' /></td>
                                <td><i onclick=\"editAddress($row[id],this)\" class='fa fa-pencil-square-o' title='ثبت تغییرات رایانامه'></i></td> 
                                <td><i onclick=\"deleteAddress($row[id],this)\" class='fa fa-trash-o deletUser' title='حذف کاربر' ></i></td>
                            </tr>";

                    $i++;
                    echo"</form>";
                }
            ?>

</tbody>
  • 写回答

2条回答 默认 最新

  • douan4106 2016-02-11 19:11
    关注

    In the addresstable.php file you should put the table tag inside the form, the addressListForm id is now unreachable (it's obvious in the syntax highlighting of source too).

      <table>
        <tr>
          <td>
            <form ...></form>
          </td>
        </tr>
    
        <tr>
          <td>
            <form ...></form>
          </td>
        </tr>
      </table>
    

    if you have multiple forms put each one in a new <tr><td> , </td></tr>

    change it to:

                    <?php
                        $i=1;
                        $results=mysqli_query($dbCnn,"select * from addresses");
                        while( $row=mysqli_fetch_array($results,MYSQLI_ASSOC))
    
                        { 
                            echo "<tr id="addressListForm">
    
                                           <td>
                                            <input type='hidden' value='$row[id]' name='id'/> 
                                           $i</td>
                                           <td><input name='title' type='text' value='$row[title]' style='width:60px'  /></td>
                                           <td><input name='address' type='text' value='$row[address]' style='width:100%' /></td>
                                           <td><input name='tel' type='text' value='$row[phone]' required='required' style='width:100px' /></td> 
                                           <td><input name='fax' type='text' value='$row[fax]' required='required' style='width:100px' /></td>
                                           <td><i onclick=\"editAddress($row[id],this)\" class='fa fa-pencil-square-o' title='ثبت تغییرات رایانامه'></i></td> 
                                           <td><i onclick=\"deleteAddress($row[id],this)\" class='fa fa-trash-o deletUser' title='حذف کاربر' ></i></td>
    
                                 </tr>";
    
                        $i++;
                    }
                ?>
    
    </tbody>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类