Home » Jquery » PHP can't get post data from jQuery dynamic method-Exceptionshub

PHP can't get post data from jQuery dynamic method-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I use .after method in Jquery to insert the html element.

This is my Jquery Code

$('#add_terms').click(function () {
  var i = $('#terms>textarea').length;
  $terms = $('#terms' + i);
  i++;
  console.log($terms);
  $terms.after('<br><br>' + i + '.    <textarea id="terms' + i + '" name="terms[]" ' + 'cols="60" rows="2" style="vertical-align:middle;"></textarea>');
})

My html:

 <table width="98%" cellspacing="1" cellpadding="3" style="border-collapse:separate; border-spacing:0px 10px;">
<form method="post" enctype="multipart/form-data" name="form1" id="form1" action='' target="_self">
<tr>
  <td align="center"> terms</td>
  <td id="terms">
    1.
    <textarea id="terms1" name="terms[]" cols="60" rows="2"
      style="vertical-align:middle;"><?php echo $terms1?></textarea>
    <br><br>
    2.
    <textarea id="terms2" name="terms[]" cols="60" rows="2"
      style="vertical-align:middle;"><?php echo $terms2?></textarea>
    <br>

    <input id="add_terms" name="add_terms" type="button" class="bt-add" value="add" style="margin-top:10px">
  </td>
</tr>
<tr>
<td colspan="2" align="center">
<input id="add" name="add" type="submit">
<input id="clear" name="clear" type="reset"  class="bt-return">
</td>
</tr>
</form>
</table>

I post the form,then I can get the value of terms1 and terms2 with using

print_r($_POST[‘terms’]);

However, I can’t get the value of terms3, terms4.

How to&Answer:

Hope this help you.

<form method="post" enctype="multipart/form-data" name="form1" id="form1" action='' target="_self">
  <td align="center"> terms</td>
  <td id="terms">
    1.
    <textarea id="terms1" name="terms[]" cols="60" rows="2"
      style="vertical-align:middle;"><?php echo $terms1?></textarea>
    <br><br>
    2.
    <textarea id="terms2" name="terms[]" cols="60" rows="2"
      style="vertical-align:middle;"><?php echo $terms2?></textarea>
    <br>

    <input id="add_terms" name="add_terms" type="submit" class="bt-add" value="add" style="margin-top:10px">
  </td>
</form>