Ask js to dynamically add each field in the table as input, but cannot submit value 1: Dynamically add js code lines
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 a specified position in the table.
Syntax tableObject. insertRow (index)
Return a TableRow value, indicating the newly inserted row.
Description
This method creates a new TableRow object, indicating a new
And insert it into the specified position in the table.
The new row will be inserted before the row where the index is located. If the index
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, which is itself inserted into the table.
Num = document. getElementById ("tbl"). rows. length;
R = tbl. insertRow (num-2); // Insert the last 2nd rows
Throw
If the index is smaller than 0 or greater than or equal to the number of rows in the table, this method throws a DOMException code INDEX_SIZE_ERR. */
Row. id = "tr" + index;
C1 = row. insertCell (-1); // Insert column td, insert one by one, and write code 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;
II. FORM content
3. submit the key code of proinsert. php on the page
If ($ _ POST ["mysubmit"] = 'submit '){
$ 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 prompt: '. mysql_error ());
}
Header ("Location: detail. php? Enname = $ enname ");
}
Mysql_close ($ con );
Thank you for your help.
Reply to discussion (solution)
Is there a control with the same name in your form? (Check the html source file by yourself)
According to php conventions, the form control with the same name should be represented in arrays.
That is, name = 'uty' to write name = 'uty []'