0

I can dynamically add table row with textbox using the code below.

How can I get the value from each textbox added, so that I can send it to my database.

Jsfiddle.net/leftstick/DVEXG

var index = 1;
function insertRow(){
        var table=document.getElementById("myTable");
        var row=table.insertRow(table.rows.length);
        var cell1=row.insertCell(0);
        var t1=document.createElement("input");
            t1.id = "txtName"+index;
            cell1.appendChild(t1);
        var cell2=row.insertCell(1);
        var t2=document.createElement("input");
            t2.id = "txtAge"+index;
            cell2.appendChild(t2);
        var cell3=row.insertCell(2);
        var t3=document.createElement("input");
            t3.id = "txtGender"+index;
            cell3.appendChild(t3);
        var cell4=row.insertCell(3);
        var t4=document.createElement("input");
            t4.id = "txtOccupation"+index;
            cell4.appendChild(t4);
  index++;

}
4
  • You haven't given nearly enough detail. Is this Web Forms? MVC? MVC Core? Nancy? A SPA communicating to Web API? Commented Aug 11, 2017 at 17:26
  • If I were to assume this is webforms we're talking about. Then it would be better to add conrols in code behind. Either dynamically or in a Repeater Control. Commented Aug 11, 2017 at 18:25
  • @mason It's webform Commented Aug 11, 2017 at 18:38
  • try using ajax jquery calls? Commented Aug 12, 2017 at 5:20

1 Answer 1

1

Use some code like this:

var value = Request.Form["txtName1"];
Sign up to request clarification or add additional context in comments.

2 Comments

How can this get all the values from each textbox
@NiangMoore Each textbox should have a name attribute set. Then call Request.Form and pass in the appropriate name.

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.