0

I have this form code to dynamically add rows. How can I add a date dynamically?

<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);

        }

        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')" />

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

</BODY>
</HTML>

This the code for adding row dynamically

This is the code for calendar

<script language="JavaScript" src="calendar_us.js"></script>
    <link rel="stylesheet" href="calendar.css">

<INPUT type="text" name="testinput" /> 
<script language="JavaScript">

    new tcal ({

        // form name

        'formname': 'testform',

        // input name

        'controlname': 'testinput'
    });

    </script>
2
  • you can use template feature instead of adding by javascript , and better use jquery Commented May 25, 2011 at 11:18
  • 1
    and you can add date just as you are adding textbox Commented May 25, 2011 at 11:19

1 Answer 1

2

add a new cell for example,

var cell4 = row.insertCell(3);
cell4.innerHTML = new Date();

.

<TR>
  <TD><INPUT type="checkbox" name="chk"/></TD>
  <TD> 1 </TD>
  <TD> <INPUT type="text" /> </TD>
  <TD> <INPUT type="text" name="testinput" /></TD>
</TR>

can you explain where to insert the date?

Sign up to request clarification or add additional context in comments.

2 Comments

the date has to be inserted next to cell 3
add a cell in table and get help from calendar_us.js's manual. if new cell is not possible then create a new element and append it like before u did. give it's name as expected by ur js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.