0

请帮助我,如何在单击表格中的编辑以填写表单弹出编辑的文本框 ID 时获取值 ID。示例当我单击编辑第一行时,如何获取值“ID01”以在表单编辑中填写文本框 ID。这是我的网站和代码:http ://hoangnguyen1612.byethost4.com/

  <!DOCTYPE html>
<?php
    include("Library/MyLibrary.php");
?>
<html><head>
        <meta charset='utf-8'/>
        <title>Home</title>
        <link rel="stylesheet" type="text/css" href="css/QuanLyKhachHang.css">
        <script src="jq/jquery.min.js"></script>
        <script src="jq/jquery-ui.min.js"></script>

        <script>
            function kiemtrarong()
            {
                if(document.getElementById("makhachhang").value == "")
                {

                    alert('Please enter id');
                    document.getElementById("makhachhang").focus();
                    return false;
                }
                else
                if(document.getElementById("tenkhachhang").value == "")
                {
                    alert('Please enter name');
                    document.getElementById("tenkhachhang").focus();
                    return false;   
                }
                else
                if(!confirm("Do you want to add?"))
                {
                    return false;
                }
            }
        </script>
        <script language="javascript">
        $(document).ready(function(){
            $('#makhachhang').focus();
            (function($){
                //Căn giữa phần tử thuộc tính là absolute so với phần hiển thị của trình duyệt, chỉ dùng cho phần tử absolute đối với body
                $.fn.absoluteCenter = function(){
                    this.each(function(){
                        var top = -($(this).outerHeight() / 2)+'px';
                        var left = -($(this).outerWidth() / 2)+'px';
                        $(this).css({'position':'absolute', 'position':'fixed', 'margin-top':top, 'margin-left':left, 'top':'50%', 'left':'50%'});
                        return this;
                    });
                }
            })(jQuery);

            $('a#show-popup').click(function(){
                //Đặt biến cho các đối tượng để gọi dễ dàng
                var bg=$('div#popup-bg');
                var obj=$('div#popup');
                var btnClose=obj.find('#popup-close');
                //Hiện các đối tượng
                bg.animate({opacity: 0.9},0).fadeIn(400); //cho nền trong suốt

                obj.fadeIn(400).draggable({cursor:'move',handle:'#popup-header'}).absoluteCenter(); //căn giữa popup và thêm draggable của jquery UI cho phần header của popup
                //Đóng popup khi nhấn nút
                btnClose.click(function(){
                    bg.fadeOut(200);
                    obj.fadeOut(200);
                });
                //Đóng popup khi nhấn background
                bg.click(function(){
                    btnClose.click(); //Kế thừa nút đóng ở trên
                });
                //Đóng popup khi nhấn nút Esc trên bàn phím
                $(document).keydown(function(e){
                    if(e.keyCode==27){
                        btnClose.click(); //Kế thừa nút đóng ở trên
                    }
                });
                return false;
            });
        });
        </script>
         <script>
        function kiemtranhapso(e)
        {
            var unicode= e.keyCode;
            if (unicode!=8)             //nếu phím không là backspace
            { 
                if (unicode<48||unicode>57)     //nếu không phải là phím số
                return false;           //vô hiệu hóa phím nhấn
            }
        }
        </script>
    </head>
    <?php error_reporting (E_ALL ^ E_NOTICE); ?>
    <?php
        session_start();
        header("Content-Type: text/html; charset=utf-8");
        $id= $_POST[id];
        $name = $_POST[name];

        $duongdan = "Database/database.txt";
        $noidung = $id."|".$name."\n";              
        if($_POST[bttthem])
        {
            if($id == "" || $name=="")
                return;
            if(ghifile($duongdan,$noidung))
            {
                echo "<script>window.onload = function()
                    {
                        alert('Done!')
                    }
                </script>";
            }
            else
            {

                echo "<script>window.onload = function()
                    {
                        alert('Error!')
                    }
                </script>";
            }
        }
    ?>
    <body>
    <form name="form1" method="post" onSubmit="return kiemtrarong()">
    <div id="main">
        <div id="title">
            LIST
        </div>
        <div style="margin-top: 50px">
            <table align="center" cellspacing="10px">
                <tr>
                    <td class="tdmain" style="width: 150px">ID</td>
                    <td class="tdmain" style="width: 200px">Name</td>
                </tr>           
                    <?php
                        $mang= array();
                        $f= fopen("Database/database.txt","r");
                        while($l=fgets($f))
                        {
                            array_push($mang,explode("|",$l));
                        }
                        fclose($f);
                        // duyệt mảng và in
                        for($i=0;$i<count($mang);$i++)
                        {
                            echo "<tr>";
                            for($j=0;$j<count($mang[$i]);$j++)
                            {
                                ?>
                                <td  style="background-color: #666; color:#FFF; font-size:14px; height: 28px ;text-align:center;border-radius: 5px;">
                                <?php echo $mang[$i][$j] ?>
                                </td>       
                                <?php
                            }
                            ?>
                             <td  style="background-color:#666; font-size:14px; text-align:center; color:#FFF; border-radius: 5px;">
                                <a href="#" style="color:#FFF; margin-right: 20px" id="show-popup">Edit</a>

                    </td>
                            <?php
                            echo "</tr>";
                        }
                    ?>
            </table>
        </div>
    </div>

    <!-- -->
    <div id="popup-bg"></div>
    <div id="loading"></div>
    <div id="popup">
        <div id="popup-header"><span id="popup-close" title="Close">Close</span>
        <div style="margin-bottom: 20px;"></div>
            <div id="headeradd">Edit</div>
        </div>
        <div id="popup-content">
            <table cellspacing="20px">
                <tr>
                    <td class="tdleft">
                        ID
                    </td>
                    <td>
                        <input type="text" class="tdright" id="makhachhang" name="id" max="5"/>
                    </td>
                </tr>
                <tr>
                    <td class="tdleft">
                        Name
                    </td>
                    <td>
                        <input type="text" class="tdright" id="tenkhachhang" name="name"/>
                    </td>
                </tr>
                   <tr>
                            <td colspan="2" align="center">
                                <input type="submit" id="bttthemkh" value="Edit" name="bttthem"/>
                            </td>
                        </tr>
            </table>
        </div>
    </div>
    </form>
    </body>
</html>
4

0 回答 0