www.webdeveloper.com
Results 1 to 2 of 2

Thread: Dynamic table need only four row

Hybrid View

  1. #1
    Join Date
    Mar 2014
    Posts
    1

    Dynamic table need only four row

    I need a dynamic table by javascript , which add row dynamically. But I need dynamic table will show latest four row .Older row will not show . I don't need more than four row.

    Here is my code to display row:

    $('#history').append('<tr><td>'+labordate+'</br>'+ formattedStart+'</td><td>'+formattedEnd+'</td><td>'+lengthFormatted+'</td><td>'+timeBetweenFormatted+'</td></tr>')


    Thanks

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,689
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function Add(flds){
     var t=document.getElementById('tst'),tr=document.createElement('TR'),td,trs,z0=0;
     for (;z0<flds.length;z0++){
      td=document.createElement('TD');
      td.innerHTML=flds[z0];
      tr.appendChild(td);
     }
     t.appendChild(tr);
     trs=t.getElementsByTagName('TR');
     while (trs.length>4){
      t.removeChild(t.getElementsByTagName('TR')[0]);
     }
    }
    /*]]>*/
    </script></head>
    
    <body>
    <table border="1">
     <tbody id="tst">
       <tr><td>'+labordate+'</br>'+ formattedStart+'</td><td>'+formattedEnd+'</td><td>'+lengthFormatted+'</td><td>'+timeBetweenFormatted+'</td></tr>
     </tbody>
    <input type="button" name="" value="ADD ROW" onclick="Add(['field 1','field 2','field 3','field 4']);"/></table>
    
    
    </body>
    
    </html>
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles