Jump to content

Get values from dynamically added textboxes and save to database


geekisthenewsexy

Recommended Posts

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>

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

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">?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.