Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Why Can't I receive POST value of dynamic added input text box?
- <script type="text/javascript">
- function add_ele() {
- // For Internet Explorer
- try {
- el = document.createElement("<input type='text' name='cat[]' >");
- }
- // For other browsers
- catch (e) {
- el = document.createElement('input');
- el.setAttribute('type', 'text');
- el.setAttribute('name', 'cat[]');
- }
- document.getElementById('cate').appendChild(el);
- }
- </script>
- <form action='submit.php' method='POST' enctype='multipart/form-data'>
- <div id='cate' style='width:100px'>
- <input type='text' name='cat[]' value='kjkj'>
- </div>
- </form>
- <a href='#' onClick="return add_ele()">Add Another</a>
- $p_cat = $_POST['cat'];
- foreach ($p_cat as $p_cate ) {
- echo "$p_cate . <br>";
- }
- <script type="text/javascript">
- function addElement() {
- var input = document.createElement('input');
- input.setAttribute('type', 'text');
- input.setAttribute('name', 'cat[]');
- input.setAttribute('value', 'some value');
- document.getElementById('cate').appendChild(input);
- // We need to return false so the href isn't followed.
- return false;
- }
- </script>
- <form action="submit.php" method='POST' enctype="multipart/form-data">
- <div id="cate" style="width: 100px">
- <input type="text" name="cat[]" value="kjkj">
- </div>
- </form>
- <a href="#" onclick="return addElement()">Add Another</a>
Add Comment
Please, Sign In to add comment