javascript - Updating html table with input -


i learning js, html, css, , general web development first time , wanted create simple (or thought) table use keeping track of items have.

essentially want make dynamically-sized table can take , save input.

i thinking of way make javascript function in order add tags tables input given. have seen personal website developer had input boxes submit button, causes data added in table in html file's table.

for instance, if have:

<table id="inventory">   <thead>     <tr>       <th>item name</th>       <th>item number</th>       <th>item color</th>     </tr>   </thead> </table> 

would possible me add

<tr class = "boxtype">   <th>boxv1</th>   <th>#1111</th>   <th>blue</th> </tr> 

the above block table using javascript , inputs?

i tried making addrows method after snooping around web, , created temporary version of table empty when refreshed (meaning wasn't put code, rather added on session), want permanently stick table if possible.

edit: thoughts have:

i feel can done if make <tbody id ="list"> , use form of innerhtml add <tr> block in?

maybe using php form in order update html table block?

thank you!

use innerhtml or jquery html() function , localstorage keep track of update dom content. remember reload old data on page load. see full example:

http://jsbin.com/voroku/edit?html,output

html input:

<input type="text" id="one"> <input type="text" id="two"> <input type="text" id="three"> <button onclick="addrow()">add</button> 

js function:

$( document ).ready(function(){   $('#screen').html(localstorage.getitem("data"));  });  function addrow(){       var str = '<tr class = "boxtype">\                  <td>'+$('#one').val()+'</td>\                  <td>'+$('#two').val()+'</td>\                  <td>'+$('#three').val()+'</td>\                  </tr>';       $('#screen').append(str);        localstorage.setitem("data", $('#screen').html());     } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -