Ask JS dynamically add each field of the table input, but cannot submit the value

Source: Internet
Author: User
One: Dynamically add the line JS code
var index;
index = 1;
function InsertRow () {
var S1 = " ";
var s2 = " ";
var s3 = " ";
var S4 = " ";
var S5 = " ";
var s6 = " ";
var s7 = " ";
var s8 = " ";
var S9 = " ";
var s10 = "";

var table = document.getElementById (' table1 ');
row = Table.insertrow (index);
The/*insertrow () method is used to insert a new row at the specified position in the table.
Syntax Tableobject.insertrow (index)
The return value returns a TableRow that represents the newly inserted row.
Description
This method creates a new TableRow object that represents a new
tag, and insert it into the specified position in the table.
The new row will be inserted before the line of index. If index
is equal to the number of rows in the table, the new row is appended to the end of the table.
If the table is empty, the new row is inserted into a newSegment, the segment itself is inserted into the table.
num = document.getElementById ("tbl"). Rows.length;
R = Tbl.insertrow (num-2); Bottom line 2nd insert
Thrown
If the parameter index is less than 0 or greater than the number of rows in the table, the method throws a Domexception exception with the code INDEX_SIZE_ERR. */
Row.id = "TR" + index;
C1 = Row.insertcell (-1);//Insert Column TD, one insert, code write with innerHTML
c1.innerhtml = S1;

C2 = Row.insertcell (-1);
c2.innerhtml = s2;

C3 = Row.insertcell (-1);
c3.innerhtml = S3;


C4 = Row.insertcell (-1);
c4.innerhtml = S4;

C5 = Row.insertcell (-1);
c5.innerhtml = S5;

C6 = Row.insertcell (-1);
c6.innerhtml = S6;

C7 = Row.insertcell (-1);
c7.innerhtml = s7;

C8 = Row.insertcell (-1);
c8.innerhtml = S8;

C9 = Row.insertcell (-1);
c9.innerhtml = S9;

C10 = Row.insertcell (-1);
c10.innerhtml = S10;

}
function Delrow (index) {

var table = document.getElementById (' table1 ');
Table.deleterow (document.getElementById ("tr" + index). RowIndex);
This.index = this.index-1;


Two. Form content


Three. Submit page proinsert.php key code
if ($_post["Mysubmit"]== ' commit ') {
$exec = "Replace into profile (Id,enname,chname, Duty, Place,ephone,sec, Sphone, Olset, Olex,vpnex,tokenex,person,dtime)
VALUES
(' $_post[id] ', ' $_post[enname] ', ' $_post[chname ', ' $_post[duty] ', ' $_post[place ', ' $_post[ephone] ', ' $_post[sec ', ' $_post[sphone] ', ' $_post[olset] ', ' $_post[olex] ', ' $_post[vpnex] ', ' $_post[tokenex ' ', ' $_post[person ', ' Now () ');
if (!mysql_query ($exec, $con))
{
Die (' Database error hint: '. mysql_error ());
}

Header ("Location:detail.php?enname= $enname");
}
Mysql_close ($con);





Thank you for your help.


Reply to discussion (solution)

You have the same name control in your form? (Look at the HTML source file yourself)
As per PHP convention, form controls with the same name are represented in an array way
That name= ' duty ' to write Name= ' duty[] '

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.