geekisthenewsexy Posted September 22, 2010 Share Posted September 22, 2010 hello, i'm actually doing a javascript here to create dynamic textboxes when a button is clicked. now my problem is, how to get all the values from these textboxes and save these values altogether in a column on the table.. i know few php coding methods like $_POST in handling values from txtboxes and saving it to database but it doesn't include working with javascript and dynamic textboxes.. and i'm actually doubtful if this is possible..so any help from you guys i would deeply appreciate. heres my code: <html> <head> <script type="text/JavaScript"> function AddTextBox() { document.getElementById('container').innerHTML+='<input type="text" name="block"><br>'; } </script> </head> <body> <input type="text" name="block"> <div id="container"></div> <br> <button onclick="AddTextBox();">Add another textbox</button> </body> </html> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 22, 2010 Share Posted September 22, 2010 The name attribute either needs to be a unique name (so that all the values will be submitted, not just the last one) or you need to use an array name - http://www.php.net/manual/en/faq.html.php#faq.html.arrays Quote Link to comment Share on other sites More sharing options...
geekisthenewsexy Posted September 22, 2010 Author Share Posted September 22, 2010 yeah i made a few tests and that's exactly what happened, only the last one got submitted. OK, but i kind of not good in arrays..i get confused. but about the attribute being a unique name, is this like for every <input type="text" name="block"> the name should be different?as in <input type="text" name="block1"><input type="text" name="block2">? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 22, 2010 Share Posted September 22, 2010 Just use an array - <input type="text" name="block[]" Quote Link to comment 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.