1

I need to automatically create more columns when am clicking a button.

I have an addmember button. When am clicking that button, the text boxes for name of the member, fathers name, mother name and DOB should be created.

Can anyone help me in doing this.

EDIT

I need to keep the column name as such and add text boxes.

EDIT

Columns should be added and not rows. That too only text fields should be added.

EDIT

Can anyone help me in finding the solution.

This is what i want::

Add Memeber- Button

Name of group member textbox11 textbox12 textbox13 Father name textbox21 textbox22 textbox23 Mother name textbox31 textbox32 textbox33 DOB textbox41 textbox42 textbox43

First and second column should remain there evrytime.

When i click the "add member" button for the first time the textbox12, textbox22, textbox32, textbox42 should appear. And when clicked for the second time textbox13, textbox23, textbox33 and textbox43 should also appear.

Please can anyone help me in solving this.

Thanks in advance, Amith

EDIT

Can anyone help me in solving this problem. Please.....

2
  • 3
    You should really avoid using the FONT tag, use SPAN instead. Commented Nov 24, 2011 at 9:45
  • Are you using jQuery or just plain JavaScript? Commented Nov 24, 2011 at 9:48

3 Answers 3

2

Append new rows dynamically using Javascript.

<script>
    function addMember() {
        var table = document.getElementById("member_table");
        table.innerHTML =  table.innerHTML + "<tr> ... your table fields here ...</tr>"

    }
</script>

<input name="addMember" type="button" name="AddMember" value='Add Member' onclick="addMember()"/>
Sign up to request clarification or add additional context in comments.

6 Comments

Seems to work for me. Did you change ... your table fields here ... in my example to real HTML?
yes i have added my html code where u mentioned. But it is showing syntax error. This is the code.
function addMember() { var table = document.getElementById("member_table"); table.innerHTML = table.innerHTML + " <tr> <td align="center" width="10%">08. </td> <td width="30%" align="right">Name of the group member : <FONT color="red">*</FONT></td> <td width="30%" class="fieldcellwithinputwide" align="left" ><INPUT type="text" /></td> </tr> <tr> <td align="center" width="10%">09. </td> "}
you are using double quotes in HTML you're adding. Javascript interprets first double quote as end of the string, and that causes syntax error. Switch to single quotes in appended HTML, or escape double quotes using backslash.
I have replaced the double quotes qith single quotes as below. Even then it is not working function addMember() { var table = document.getElementById("member_table"); table.innerHTML = table.innerHTML +" <tr><td align='center' width='10%'>08. </td> <td width='30%' align='right'>Name of the group member : </td> <td width='30%' class='fieldcellwithinputwide' align='left' ><INPUT type='text' /></td> </tr>" }
|
1

you can use something like this;

<input name="addMember" type="button" name="AddMember" value='Add Member' onclick="addRow('tableID')"/>


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("font");
            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);

        }

Comments

1

You can try using this function:

function addMember()
{
    var tblBody = document.getElementById('member_table').tBodies[0];
    var newRow = tblBody.insertRow(-1);
    var newCell0 = newRow.insertCell(0);
    var newInput = document.createElement('input');
    newInput.type = 'text';
    newInput.value = 'mothers name';
    newInput.style.color = 'blue';
    newCell0.appendChild(newInput);
    /* add more options like this ...*/
}

Comments

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.