how to limit the additions field?

Discussion in 'JavaScript' started by s.jns, Oct 30, 2010.

  1. #1
    Hi,
    If someone here is willing to help me I would really appreciate

    how to limit the addition of columns in the following html code, let say only up to 5 only?
    <script type="text/javascript"><!--
    function addFriend() {
    	var tbl = document.getElementById('my_friends');
    	var iteration = tbl.tBodies[0].rows.length;
    	newRow = tbl.tBodies[0].insertRow(-1);
    	var newCell = newRow.insertCell(0);
    	newCell.innerHTML = '<?php echo $entry_friend; ?>';
    	var newCell1 = newRow.insertCell(1);
    	var el = document.createElement('input');
    	el.type = 'text';
    	el.name = 'friends[]';
    	el.size = 30;
    	el.maxlength = 45;
    	newCell1.appendChild(el);
    //	if (newCell > 2) tbl.addCell(newCell + 1);
    }
    
    function removeFriend() {
    	var tbl = document.getElementById('my_friends');
    	var lastRow = tbl.rows.length;
    	if (lastRow > 2) tbl.deleteRow(lastRow - 1);
    }
    //--></script>
    Code (markup):
    Thanks in advance
     
    s.jns, Oct 30, 2010 IP