Page 1 of 1

PHP/JS integration question

Posted: Mon Apr 03, 2006 5:43 am
by mattcooper
Hello again.

Below is some JScript that creates new form elements (Thanks for the tip, Feyd, this was the right way to do it in the end!). When I submit the page, the contents of the textfields will be used to construct buttons on a preview page. Eventually, the contents will end up in a database.

Code: Select all

function addT(){
var root = document.getElementById('container');
var j=root.getElementsByTagName('div').length+1;
var clone = root.getElementsByTagName('div')[0].cloneNode(true);
var txt=clone.getElementsByTagName('input');
txt[0].name='link'+j;txt[0].value='URL';
txt[1].name='label'+j;txt[1].value='label';
root.appendChild(clone)
}
I am having a problem envisaging how to get this to happen. For example, the user creates three sets of textfields and submits them to the form handler - how, then, does the form handler deal with the $_POST information if it doesn't know how many sets of textfields are coming? I'm guessing that the solution would be an array, but those of you who are familiar with older posts from me will know that I'm crap with arrays!

Any suggestions would be greatly appreciated!

Thanks in advance :)

Posted: Mon Apr 03, 2006 5:48 am
by patrikG

Posted: Mon Apr 03, 2006 7:16 am
by mattcooper
Thanks - it works for the entire form except for the JS-generated elements - it only dumps data for the last form element created and misses the others. Since my understanding of arrays is soooo bad, can somebody please tell me why this is happening??

Thanks again!

Posted: Mon Apr 03, 2006 7:37 am
by mattcooper
Whoops, it was a JS error not a PHP one... all is well on that front now. Any hints on insertion of the resultant fields into the database? Similar problem, I expect, with a similar solution?