Giri J Posted January 15, 2009 Share Posted January 15, 2009 Hi, I have a html + javascript code like this : <html> <head> <title>Dynamic Form test pge</title> <script language="javascript"> function changeIt() { var i = 1; my_div.innerHTML = my_div.innerHTML +"<br><input type='text' name='mytext'+ i><br/>" } </script> </head> <body> <form action="test-js-php.php" method="post"> <input type="button" value="test" onClick="changeIt()"> <input type="submit" value="submit"> <div id="my_div"> </div> </body> If you save this as a html file and click on test button it will keep adding the text fields. Now, This is my problem: > I want to enter some data into those text fields > and When I submit it I want the data from the HTML form to my PHP. My php code is like this: <?php $t1=$_POST['mytext1']; $t2=$_POST['mytext2']; $t3=$_POST['mytext3']; echo $t1.$t2.$t3; ?> Please help me. I'm not that good at Javascript. Quote Link to comment https://forums.phpfreaks.com/topic/140955-solved-im-unable-to-get-the-values-from-the-html-form-to-php-please-help/ Share on other sites More sharing options...
sasa Posted January 15, 2009 Share Posted January 15, 2009 change your js code and close form tag <html> <head> <title>Dynamic Form test pge</title> <script language="javascript"> var i = 0; function changeIt() { i = i+1; my_div.innerHTML = my_div.innerHTML+"<br><input type='text' name='mytext"+i+"'><br/>" } </script> </head> <body> <form action="test-js-php.php" method="post"> <input type="button" value="test" onClick="changeIt()"> <input type="submit" value="submit"> <div id="my_div"> </div> </form> </body> Quote Link to comment https://forums.phpfreaks.com/topic/140955-solved-im-unable-to-get-the-values-from-the-html-form-to-php-please-help/#findComment-737784 Share on other sites More sharing options...
Giri J Posted January 16, 2009 Author Share Posted January 16, 2009 Thanks a lot mate. It solved my problem :) I'm successfully able to get the data from the dynamically generated text fields Much Appreciated. One final request: is there a site where we can quickly brush up JS skills with some good examples? Please let me know. Quote Link to comment https://forums.phpfreaks.com/topic/140955-solved-im-unable-to-get-the-values-from-the-html-form-to-php-please-help/#findComment-738208 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.