HTML JS Gets the value of all input in the table passed to the front end

Source: Internet
Author: User
Tags string back

1. Get the Table object

2. Loop, column loop, and then iterate through the input values in each lattice

3. Connect with a connector

4. Place inside the hidden field of the form.

5. Pass to the background.

JS Code: NOTE: 1.input must be followed by [0] Otherwise the value 2 cannot be removed. In the double quotation mark of JS cannot be changed to "" and {} in quotation marks will also be recognized error. Pass the string back to background processing

functiongetinfofromtable () {varTableinfo = ""; varTableobj = document.getElementById ("booktable"); //alert (tableObj.rows.length);          //getting data from the second row           for(vari = 2; i < tableObj.rows.length; i++) {//traverse all row of table             for(varj = 0; J < Tableobj.rows[i].cells.length; J + +) {//iterate through each column in rowTableinfo + = tableobj.rows[i].cells[j].getelementsbytagname ("input") [0].value;//get the contents of a cell in a tableTableinfo + = ",";        }} alert (Tableinfo); }                 functionAddtablerow () {varTable = document.getElementById ("booktable");//Get the Custom Table objectNewRow = Table.insertrow ();//Adding RowsNewcell1= Newrow.insertcell ();//Adding ColumnsNewcell2=Newrow.insertcell (); NewCell3=Newrow.insertcell (); NEWCELL4=Newrow.insertcell (); Newcell2.colspan=2; Newcell1.innerhtml= "<input required= ' required ' type= ' text '/>";//Add DataNewcell2.innerhtml= "<input required= ' required ' type= ' text '/> '; Newcell3.innerhtml= "<input required= ' required ' onkeyup= ' Jhshnumbertext (this) '/> '; Newcell4.innerhtml= "<input required= ' required ' onkeyup= ' Jhshnumbertext (this) '/> '; }                 </script>

HTML JS Gets the value of all input in the table passed to the front end

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.