Adding data to a table with native DOM implementations
<Script>document.getElementById ("Submit"). onclick=function(){ //Get input node varname=document.getElementById ("Iname"); varEmail=document.getElementById ("Iemail"); varaddresss=document.getElementById ("iaddress"); //Create a table node varTrnode=Document.createelement ("TR"); varCheckboxnode=Document.createelement ("TD"); varNameNode=Document.createelement ("TD"); varEmailnode=Document.createelement ("TD"); varAddressnode=Document.createelement ("TD"); //Add the Created node and text content to the table varBorder=document.getElementById ("Border"); Border.appendchild (Trnode); Trnode.appendchild (Checkboxnode); Trnode.appendchild (NameNode); Trnode.appendchild (Emailnode); Trnode.appendchild (Addressnode); varCheckboxtext=Document.createelement ("input"); Checkboxtext.setattribute ("type","checkbox"); varNametextnode=document.createTextNode (Name.value); varEmailtextnode=document.createTextNode (Email.value); varAddresstextnode=document.createTextNode (Addresss.value); Checkboxnode.appendchild (Checkboxtext); Namenode.appendchild (Nametextnode); Emailnode.appendchild (Emailtextnode); Addressnode.appendchild (Addresstextnode); } </Script>
Here is the HTML
<!DOCTYPE HTML><HTMLLang= "en"> <Head><MetaCharSet= "UTF-8"><title>To edit data in a table</title> </Head> <Body> <formID= "Form1"> <ulstyle= "float:left; margin:30px 30px;list-style:none;"> <Li>Name:<inputtype= "text"ID= "Iname"></Li> <Li>Mailbox:<inputtype= "text"ID= "Iemail"> </Li> <Li>Address:<inputtype= "text"ID= "Iaddress"></Li> <Li>Add to:<inputtype= "button"value= "Add"ID= "Submit"></Li> </ul> </form> <TableBorder= "1"ID= "Border"style= "Margin:30px;border:solid 1px gray;width:400px;text-align:center;"> <Colgroup> <Colwidth= " the"/> <Colwidth= "+"/> <Colwidth= "+"/> <Colwidth= "$"/> </Colgroup> <TR> <th><inputtype= "checkbox"ID= "checkbox"></th> <thID= "Name">Name</th> <thID= "Email">Mailbox</th> <thID= "Address">Address</th> </TR> <TR> <TD><inputtype= "checkbox"></TD> <TD>Tom</TD> <TD>[Email protected]</TD> <TD>Hubei Province</TD> </TR> </Table> </Body> </HTML>
Adding data to a table with native DOM implementations