Guest User

Untitled

a guest
Aug 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. Why Can't I receive POST value of dynamic added input text box?
  2. <script type="text/javascript">
  3.  
  4. function add_ele() {
  5.  
  6. // For Internet Explorer
  7. try {
  8. el = document.createElement("<input type='text' name='cat[]' >");
  9. }
  10. // For other browsers
  11. catch (e) {
  12. el = document.createElement('input');
  13. el.setAttribute('type', 'text');
  14. el.setAttribute('name', 'cat[]');
  15. }
  16.  
  17. document.getElementById('cate').appendChild(el);
  18. }
  19. </script>
  20.  
  21.  
  22.  
  23. <form action='submit.php' method='POST' enctype='multipart/form-data'>
  24. <div id='cate' style='width:100px'>
  25. <input type='text' name='cat[]' value='kjkj'>
  26. </div>
  27. </form>
  28. <a href='#' onClick="return add_ele()">Add Another</a>
  29.  
  30. $p_cat = $_POST['cat'];
  31. foreach ($p_cat as $p_cate ) {
  32.  
  33. echo "$p_cate . <br>";
  34. }
  35.  
  36. <script type="text/javascript">
  37.  
  38. function addElement() {
  39. var input = document.createElement('input');
  40. input.setAttribute('type', 'text');
  41. input.setAttribute('name', 'cat[]');
  42. input.setAttribute('value', 'some value');
  43. document.getElementById('cate').appendChild(input);
  44.  
  45. // We need to return false so the href isn't followed.
  46. return false;
  47. }
  48.  
  49. </script>
  50.  
  51. <form action="submit.php" method='POST' enctype="multipart/form-data">
  52. <div id="cate" style="width: 100px">
  53. <input type="text" name="cat[]" value="kjkj">
  54. </div>
  55. </form>
  56.  
  57. <a href="#" onclick="return addElement()">Add Another</a>
Add Comment
Please, Sign In to add comment