0

I have table.

<tableid="mytable" >
<tr class='row'>
 <td>Name</td>
 <td><input type="textbox" name="txtName" /></td>
</tr>
</table>

I used jQuery to add new row

var a = $(".row").html();
$("#mytable > tbody:first").append("<tr class='row'>"+a+"</tr>");

This is code PHP

$_REQUEST['txtName'];

I can't get values textbox when create new rows. Please help me

6
  • can't get the values WHERE? php? javascript? Commented Feb 16, 2013 at 7:10
  • If you're trying to get the value of txtName in PHP on the same page you're adding to with jQuery, it won't work because PHP has already run its course by the time jQuery runs. If you're posting to the PHP page trying to request the value of txtName, you need to double check that your inputs are inside a form that points to your PHP page. Commented Feb 16, 2013 at 7:12
  • Your code creates two textboxes with same name property txtName. And because of that it is not giving you result in PHP. Refer Galen's answer. Commented Feb 16, 2013 at 7:14
  • Please close the input tag? Commented Feb 16, 2013 at 7:14
  • try explicitly adding tbody in your table.. Commented Feb 16, 2013 at 7:17

3 Answers 3

2

Assuming the html is correct on your server, the reason you can't get the values from new rows is that they all have the same variable name. Make the name of the input an array.

<table id="mytable" >
<tr class='row'>
 <td>Name</td>
 <td><input type="textbox" name="txtName[]"></td>
</tr>
</table>

Now all the names will be in the array $_REQUEST['txtName']

Also, don't use $_REQUEST. Use $_POST, $_GET, $_COOKIE, etc. There are security reasons.

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

Comments

0

You can't get the values in PHP probably since you can't have two text fields with the same name .

If you're adding a new field dynamically with jQuery, make sure you append a number at the end of some sort, for example txtName, txtName2, txtName3 etc...

Also, your input markup is invalid, Should be closed:

 <td><input type="textbox" name="txtName" /></td>

Comments

0

Try like this

<tableid="mytable" >
    <tr class='row'>
      <td>Name</td>
      <td><input type="textbox" name="txtName_0"></td>
    </tr>
 </table>

and each time you need to increment the name values as txtName_1,txtName_2....like that through javascript and then get them as

$REQUEST['txtName_0'],$REQUEST['txtName_1'].....or directly use loop them....

1 Comment

Please close the input tag?

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.