Jump to content

Javascript


Recommended Posts

HI i am trying to write a command to repeat a some cells. Is there any way to put the selected fields in a section and link that to my Java-script to repeat that region. I am able to do that function in HTML. I have added my code below please advise

<HTML>
<HEAD>
    <TITLE> Add/Remove dynamic rows in HTML table </TITLE>
 <SCRIPT language="javascript">
        function addRow(tableID) {
 
            var table = document.getElementById(tableID);
 
            var rowCount = table.rows.length;
            var row = table.insertRow(rowCount);
 
            var cell1 = row.insertCell(0);
            var element1 = document.createElement("input");
            element1.type = "checkbox";
            cell1.appendChild(element1);
 
            var cell2 = row.insertCell(1);
            cell2.innerHTML = rowCount + 1;
 
            var cell3 = row.insertCell(2);
            var element2 = document.createElement("input");
            element2.type = "text";
            cell3.appendChild(element2);
			
			var cell4 = row.insertCell(3);
            var element2 = document.createElement("input");
            element2.type = "text";
            cell4.appendChild(element2);
			
			var cell5 = row.insertCell(4);
            var element2 = document.createElement("input");
            element2.type = "text";
            cell5.appendChild(element2);
			
			var cell6 = row.insertCell(5);
            var element2 = document.createElement("input");
            element2.type = "text";
            cell6.appendChild(element2);
			
			
 
 
        }
 
        function deleteRow(tableID) {
            try {
            var table = document.getElementById(tableID);
            var rowCount = table.rows.length;
 
            for(var i=0; i<rowCount; i++) {
                var row = table.rows[i];
                var chkbox = row.cells[0].childNodes[0];
                if(null != chkbox && true == chkbox.checked) {
                    table.deleteRow(i);
                    rowCount--;
                    i--;
                }
 
 
            }
            }catch(e) {
                alert(e);
            }
        }
 
    </SCRIPT>
</HEAD>
<BODY>
 
    <INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
 
    <INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
 </br>
 <TABLE width="650px" border="1">
 <TR>
            <TD></TD>
            <TD>S/no</TD>
            <TD> Quantity </TD>
			<TD> Description </TD>
			<TD> Unit Price </TD>
			<TD> Amount </TD>

        </TR>
		</TABLE>
    <TABLE id="dataTable" width="300px" border="1">
        <TR>
            <TD><INPUT type="checkbox" name="chk"/></TD>
            <TD><div contenteditable> 1 </div></TD>
            <TD> <INPUT type="text" /> </TD>
			<TD> <INPUT type="text" /> </TD>
			<TD> <INPUT type="text" /> </TD>
			<TD> <INPUT type="text" /> </TD>

        </TR>
    </TABLE>
 
</BODY>
</HTML>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...