simcityfreak4 Posted February 6, 2008 Share Posted February 6, 2008 This is the code I use to add dynamic text boxes: <script> var arrInput = new Array(0); var arrInputValue = new Array(0); function addInput() { arrInput.push(arrInput.length); arrInputValue.push(""); display(); } function display() { document.getElementById('parah').innerHTML=""; for (intI=0;intI<arrInput.length;intI++) { document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]); } } function saveValue(intId,strValue) { arrInputValue[intId]=strValue; } function createInput(id,value) { return "<input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'><br /><br />"; } function deleteInput() { if (arrInput.length > 0) { arrInput.pop(); arrInputValue.pop(); } display(); } </script> How can I get the results of all the text boxes the user adds and store them in MySQL? Link to comment https://forums.phpfreaks.com/topic/89799-solved-dynamic-text-boxes-php/ Share on other sites More sharing options...
PHP Monkeh Posted February 6, 2008 Share Posted February 6, 2008 You'd have to name the fields, let's say for arguments sake "input[]". The reason you add [] on to the end is that you will create an array. Take this example: <?php if(isset($_POST['submit'])) { print_r($_POST['field']); } ?> <form action="form.php" method="post"> <input type="text" name="field[]" value="test1"> <input type="text" name="field[]" value="test2"> <input type="submit" name="submit"> </form> You could loop through the array if you wanted but I just wanted to show the values of it quickly. Once they submit the form or click a "Save" button, you could then post the form and use PHP to go through the array and insert the data to a table Or do whatever you want with it. Link to comment https://forums.phpfreaks.com/topic/89799-solved-dynamic-text-boxes-php/#findComment-460144 Share on other sites More sharing options...
simcityfreak4 Posted February 6, 2008 Author Share Posted February 6, 2008 Thanks, that worked! Link to comment https://forums.phpfreaks.com/topic/89799-solved-dynamic-text-boxes-php/#findComment-460156 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.