Hi all.
I use the following js function to dynamically create an new <tr> and <td> in my table. Then I insert an <input>. :
function testName(tableID)
{
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
//firstname
var cell1 = row.insertCell(0);
var element = document.createElement("input");
element.type = text';
element.name = 'testname';
element.id = "testname";
cell1.appendChild(element);
}
On the target php, I do $testNames = $_POST['testname'];
This gives me : Notice: Undefined index: testname
If I define this <input> manually in my table, it works fine.
Any suggestions will be appreciated!
thanks
aristos
aristos32
0
Newbie Poster
Recommended Answers
Jump to Postim not sure if its a javascript error
look at line 14 missing quote.
Jump to PostJust tested this and it works for me:
<?php var_dump($_POST); ?><html> <head> <script type="text/javascript"> function displayResult() { var table=document.getElementById("myTable"); var row=table.insertRow(0); var cell1=row.insertCell(0); var cell2=row.insertCell(1); cell1.innerHTML="New"; cell2.innerHTML="New"; var element = document.createElement("input"); element.type = 'text'; element.name = 'testname'; element.id = "testname"; cell1.appendChild(element); } </script> </head> <body> <form method=post> …
Jump to Posttry just adding an
alert(tableID);
. I cant see any difference to the one i did and that worked for me, the only difference in mine is it had a call to innerHTML but even so that was before the input was created - could still make a difference.
All 10 Replies
code739
17
Posting Whiz in Training
Biiim
182
Junior Poster
code739
17
Posting Whiz in Training
niranga
9
Junior Poster
code739
17
Posting Whiz in Training
aristos32
0
Newbie Poster
Biiim
182
Junior Poster
aristos32
0
Newbie Poster
aristos32
0
Newbie Poster
aristos32
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.