Getting A Value From Dynamically Created Textbox Through Php November 30, 2022 Post a Comment I have n number of text box (n may be any number) with same name. And I want to access the value of all the text box of that name. Ex-: Solution 1: <script> jQuery(document).ready(function($) { $('#newFieldBtn').click(function(){ var count = document.getElementById('count').value; count++; var code = '<input type="text" name="user'+count+'" />'; jQuery('#create').append(code); document.getElementById('count').value = count; </script> Copy and your html like... <form method="post" id="create"> <input type="hidden" id="count" value="0" name="count"> <input type="button" id="newFieldBtn"/> <input type="submit" name="save" value="save"/> </form> Copy and in your php code... <?php if(isset($_POST)) { $count = $_POST['count']; for($i=1;$i<=$count;$i++) { $user.$i = $_POST['user'.$i]; } } ?> Copy Solution 2: Try this one, it will show you the values : <form action="#" method="post"> <input type="text" name="user[]" /> <input type="text" name="user[]" /> <input type="text" name="user[]" /> <input type="submit" value="submit" > </form> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { foreach($_POST['user'] as $key => $value) { echo $key." has the value = ". $value."<br>"; } } ?> Copy See this in action: http://wistudat.be/try/array.php Share Post a Comment for "Getting A Value From Dynamically Created Textbox Through Php"
Post a Comment for "Getting A Value From Dynamically Created Textbox Through Php"