Form and tables | Sololearn: Learn to code for FREE!

+3

Form and tables

Hi guys! i'm newbie for html and js.. My question is about forms and tables. Can i create tables dynamically by using forms in html or js.(in the same page or onather one) is it necessary to use database? if i can pls tell me which method or way should i google it to learn?

3/30/2018 5:57:21 PM

bilal korkmaz

4 Answers

New Answer

+4

Well, technically, you can create tables from forms, but I can't really think of a situation where that's the better option to go with. What type of data will your tables consist of? I'd recommend taking time to learn jQuery also, and then go check out https://datatables.net/ <--- DataTables is a nothing less than amazing and will make your life so much easier when dealing with tables. You can populate the tables with your HTML, or you can populate it dynamically via your database. Personally, I recommend databases (learn SQL if you haven't already, and a server-side lang like PHP or NodeJS). Resources: https://datatables.net/ https://www.sololearn.com/Course/PHP/ https://www.sololearn.com/Course/SQL/ https://www.sololearn.com/Course/jQuery/ I have extensive knowledge with DataTables, so if you run into a problem, feel free to ask me and I'll do what I can to assist you with it.

+4

You can use that: <script type="text/javascript"> function createTable() { var num_rows = document.getElementById('rows').value; var num_cols = document.getElementById('cols').value; var theader = '<table border="1">\n'; var tbody = ''; for( var i=0; i<num_rows;i++) { tbody += '<tr>'; for( var j=0; j<num_cols;j++) { tbody += '<td>'; tbody += 'Cell ' + i + ',' + j; tbody += '</td>' } tbody += '</tr>\n'; } var tfooter = '</table>'; document.getElementById('wrapper').innerHTML = theader + tbody + tfooter; } </script> </head> <body> <form name="tablegen"> <label>Rows: <input type="text" name="rows" id="rows"/></label><br /> <label>Cols: <input type="text" name="cols" id="cols"/></label><br/> <input name="generate" type="button" value="Create Table!" onclick='createTable();'/> </form> <div id="wrapper"></div> You can also use the insertRow and insertCell. read more: https://developer.mozilla.org/en/Traversing_an_HTML_table_with_JavaScript_and_DOM_Interfaces http://www.w3schools.com/js/tryit.asp?filename=try_dom_table_insertrow

+1

i don't know php or sql for now but i've found a tutorial about sending data from html form to google sheets(using as a database). i'm gonna try it. Maybe i can import data from google sheets to my html table back.

0

thanks for answers