按钮单击时自动完成文本框

时间:2014-01-13 12:53:37

标签: c# asp.net

function insRow() {

    var tab = document.getElementById('POITable');
    var size = tab.rows.length;

    if (size == 1) {
        DoPostBack();
    }
    else {

        console.log('hi');
        var x = document.getElementById('POITable');
        var new_row = x.rows[1].cloneNode(true);
        var len = x.rows.length;
        new_row.cells[0].innerHTML = len;
        // var i1 = row.parentNode.parentNode.rowIndex;
        // alert(i1);


        var inp1 = new_row.cells[1].getElementsByTagName('input')[0];
        inp1.id += len;
        inp1.value = '';
        inp1.style.width = 88 + "px";
        var inp2 = new_row.cells[2].getElementsByTagName('input')[0];
        inp2.id += len;
        inp2.value = '';
        inp2.style.width = 87 + "px";
        var inp3 = new_row.cells[3].getElementsByTagName('textarea')[0];
        inp3.id += len;
        inp3.value = '';
        inp3.style.width = 105 + "px";
        inp3.style.height = 34 + "px";
        inp3.style.resize = 'none';

        var inp4 = new_row.cells[4].getElementsByTagName('input')[0];
        inp4.id += len;
        inp4.value = '';
        inp4.style.width = 78 + "px";
        var inp5 = new_row.cells[5].getElementsByTagName('input')[0];
        inp5.id += len;
        inp5.value = '';
        inp5.style.width = 87 + "px";
        var inp6 = new_row.cells[6].getElementsByTagName('select')[0];
        inp6.id += len;
        inp6.value = '';
        inp6.style.width = 63 + "px";
        var inp7 = new_row.cells[7].getElementsByTagName('input')[0];
        inp7.id += len;
        inp7.value = '';
        inp7.style.width = 84 + "px";
        x.appendChild(new_row);
    }
}



  <table ID="POITable" class="style25">
                <tr>
                    <td bgcolor="AliceBlue">
                        Sr</td>
                    <td width="80" bgcolor="AliceBlue">
                        Line Item</td>
                    <td class="style26" bgcolor="AliceBlue">
                        Material</td>
                    <td class="style27" bgcolor="AliceBlue">
                        Description</td>
                    <td class="style28" bgcolor="AliceBlue">
                        Quantity</td>
                    <td class="style29" bgcolor="AliceBlue">
                        Unit Price</td>
                    <td class="style32" bgcolor="AliceBlue">
                        VAT</td>
                    <td class="style31" bgcolor="AliceBlue">
                        Amount</td>
                    <td bgcolor="AliceBlue">
                        Delete?</td>
                </tr>
                <tr>
                    <td>
                        1</td>
                    <td >
                        <input id="Textl" type="text" />
                    </td>
                    <td >
                        <input id="Textm" type="text" />
                    </td>
                    <td class="style27">
                        <textarea ID="Textd" rows="6" cols="7" name="S2"></textarea>&nbsp;</td>
                    <td class="style28">
                        <input id="Textq" type="text" onkeyup="calculation()" />
                    </td>
                    <td class="style29">
                        <input id="Textu" type="text" onkeyup="calculation()" />
                    </td>
                    <td class="style32" id="select">
                     <select id="select" onchange="calculation()">
                     <option value="select">Select</option>
            <option value="5">5</option>
            <option value="12">12</option>
            </select>

                     </td>
                    <td class="style31">
                        <input id="Texta" type="text" />
                    </td>
                    <td>
                        <input id="Button3" type="button" value="Delete" onclick="deleteRow(this)" />
                    </td>
                </tr>
                <tr><input id="Hidden1" type="hidden" runat="server"/></tr>
            </table>

            <input type="button" id="Button1" value="Add New Line" onclick="insRow()"/>

我想在javascript代码的每一行中添加自动填充文本框...当我点击添加新行按钮然后我希望每行中的文本框应该是自动填充数据库值,无论我有哪个 那我怎么能在按钮点击动态添加它...请帮我解决方案 提前感谢你

0 个答案:

没有答案