简体   繁体   English

如何使用javascript将行输入框添加到现有的html表单中

[英]how do i add a row of input boxes, to an existing html form using javascript

I have a form which displays rows from a database table and an update button with each row. 我有一个表单,它显示数据库表中的行以及每行的更新按钮。

I need to add a blank row on a button click (ADD ENTRY) exactly like the ones above in the form and a save button with this row, like above (update button), using JavaScript. 我需要在按钮单击(ADD ENTRY)上添加一个空白行,该行与表单中的上方完全相同,并使用JavaScript在此行中添加一个保存按钮,如上述(更新按钮)。

The following is the HTML and the JS I'm using. 以下是我正在使用的HTML和JS。 This is how my page looks like: 这是我的页面的样子: 网页

<?php

include('adodb/adodb.inc.php');

echo '<h1>Mxpresso Revenue Management Solution</h1>';

echo '<img src="http://mxpresso.com/images/logo.png" alt="mxpresso logo" style="width:171px;height:108px;">';

echo '<h2>See existing records</h2>';

$db=NewADOConnection('mysql');$db->Connect("127.0.0.1", "vc", "abc", "vc");

$sql="select * from rev";
$result = $db->Execute($sql);
if ($result === false) die("failed2");
$records=array();
$count=$result->RecordCount();
echo "Total Records Found :".$count."<br>";

if($count > 0) {
    echo '<style>
          input{
             outline:none;
             border: none;
           }

           </style>

<table id="datatable" class="form" border="1" width="50%">
<col width="10%">
<col width="10%">
<col width="10%">
<col width="10%">
<col width="10%">
<tbody>
<tr>
<th><h4>OfferID</h4></th>
<th><h4>AffID</h4></th>
<th><h4>Deduction</h4></th>
<th><h4>Status</h4></th>
<th><h4>Update Entry</h4></th>
</tr>';

    while (!$result->EOF){
        $offerId=$result->fields[0];
        $affId=$result->fields[1];
        $status=$result->fields[2];
        $deduction=$result->fields[3];                                       

       echo'<form target="_blank" action ="updatecopy.php" id="myform" method="get">


            <tr>        
                        <td><input type="text" name="update_for_offerid" value='.$offerId.'></td>
                        <td><input type="text" name="update_for_affid"  value='.$affId.'></td>
                        <td><input type="text" name="deduct" value='.$deduction.'></td>
                        <td><input type="text" name="status" value='.$status.' ></td>
                        <td><input type="submit" size="23" value="Update Entry" style="color : Black;width:165px"></td>

                    </tr>

                    </form>';
        $rec=array("offerId"=>$offerId,"affiliate_id"=>$affId,"status"=>$status, "deduction"=>$deduction);
        array_push($records,$rec);
        $result->MoveNext(); 
        }
 }

 echo '</tbody>
    </table>    

    <div id="dynamicinput1">

    </div>
    <form><input type="button" value="Add Entry" style="font-family: sans-serif; font-size: 15px; color : Black;" onClick="addInput(\'dynamicinput1\');">
    </form>


        <script language="Javascript" type="text/javascript">
        var counter = 1;
        var limit = 10;

      function addInput(divName){

     if (counter == limit)  {
          alert("You have reached the limit of adding " + counter + " inputs");
     }
     else {



          var fool = document.createElement(\'form\');

          var newtable = document.createElement(\'Table\');

          var tr = document.createElement(\'tr\');
          newtable.style.border = "1px solid black";
          tr.style.width="10px";


            var td1  =  document.createElement(\'td\');
            td1.innerHTML = "<br><input type=\'text\' name=\'offerId\'>";
            td1.style.border = "1px solid black";


            var td2  =  document.createElement(\'td\');
            td2.innerHTML ="<br><input type=\'text\' name=\'affId\'>";
            td2.style.border = "1px solid black";


            var td3  =  document.createElement(\'td\');
            td3.innerHTML ="<br><input type=\'text\' name=\'status\'>";
            td3.style.border = "1px solid black";


            var td4  =  document.createElement(\'td\');
            td4.innerHTML ="<br><input type=\'text\' name=\'deduct\'>";
            td4.style.border = "1px solid black";

            tr.appendChild(td1);
            tr.appendChild(td2);
            tr.appendChild(td3);
            tr.appendChild(td4);


            newtable.appendChild(tr);

            fool.appendChild(newtable);
            fool.action = "insertcopy.php"
            var save = document.createElement(\'input\');
            save.type = "submit";
            save.value = "Save Entry";
            fool.appendChild(save);
            tr.appendchild(save);



            document.getElementById(divName).appendChild(fool);
            counter++;



     }
}
</script>';
?>
It may help you.

 $(document).ready(function() { $('a').click(function() { $('#myTable tbody').append('<tr class="child"><td><input type="text"></td><td><input type="text"></td><td<input type="text"></td><td><input type="text"></td><td><input type="text"></td><td>submit</td></tr>'); }); }); 
 input{ width:40px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <a href="javascript:void(0);">add new</a> <table id="myTable"> <thead> <tr> <td>offerID</td> <td>affid</td> <td>deduction</td> <td>status</td> <td>update entry</td> </tr> </thead> <tbody> <tr> <td>123</td> <td>231</td> <td>12</td> <td>654</td> <td>update</td> </tr> <tr> <td>123</td> <td>231</td> <td>12</td> <td>654</td> <td>update</td> </tr> <tr> <td>123</td> <td>231</td> <td>12</td> <td>654</td> <td>update</td> </tr> </tbody> </table> 

Write an sql query to add data to the table. 编写一个sql查询以将数据添加到表中。 Then you execute your sql query Example: $SQL= "INSERT INTO table_name (column_name1, column_name2...) VALUES ('$val1', '$val2')"; 然后执行SQL查询。示例:$ SQL =“ INSERT INTO table_name(column_name1,column_name2 ...)VALUES('$ val1','$ val2')”; $exeSQL=mysql_query($SQL) or die (mysql_error()); $ exeSQL = mysql_query($ SQL)或死掉(mysql_error());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTML-如何使用javascript在输入日期中增加天数? - HTML - How do I add days to an input date using javascript? 如何使用Javascript将文本框和按钮添加到表中? - How do I add text boxes and buttons into a table using Javascript? 如何从输入框中获取一些输入,放置在变量中,然后使用HTML和Javascript输出到范围ID? - How do I grab a few inputs from input boxes, place in variables, then output to a span id using HTML & Javascript? 如何在javascript中将输入字段动态添加到我的html表格行内的单元格中? - How do I dynamically add an input field into a cell inside my html table row in javascript? 如何通过HTML表单输入文本并使用Javascript从JSON文件中检索数据作为响应? - How do I input text via an HTML form and retrieve data from a JSON file as a response using Javascript? 如何在保留现有表单数据的同时使用 append 输入节点与 JavaScript 形成? - How do I append input node to form with JavaScript while keeping existing form data? 如何使用javascript将选项添加到html表单下拉列表中 - how do I add an option to a html form dropdown list with javascript 在javascript中使用来自html框的输入 - Using input from html boxes in javascript 如何从HTML表单获取用户输入并将其存储在现有的JavaScript数组中 - How can I get the user input from a HTML form and store it in an existing JavaScript array 如何将两个数字相加并将其与第三个数字相乘,并在 html 表单中以 javascript 的形式在禁用输入中显示总数? - How do I add two numbers and them multiply it with the 3rd number and show the total in a disabled input in a html form with javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM