Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamically created form elements not appearing on server side

Status
Not open for further replies.

bigS47

Programmer
Jun 29, 2006
20
CA
Hey everybody,

I'm not sure wether I should put this in the php forum or this forum, so if you know javascript and php, please help!

I am creating a form in which the user has the ability to create elements dynamically.

These elements are created using this code:
Code:
box="<input name=\"sets\" value=\"\" size=\"5\">";
//tr is defined earlier
tr.innerHTML=box;
I can see and type text into the textbox thus created, however, when I submit the form, its values do not appear in the POST data!
I have tried using the createElement and appendChild functions too, with the same result.
The javascript works, I can see the textboxes. I just don't know why I don't see these values with the php. I am sure it IS NOT the php also, but it would take too long to explain why. Is there something I should be doing extra? Is this unusual?
 
Any chance this is a nested table or another table exists on the page outside of the form tags? It could be that the wrong element is being updated. Can only guess without seeing the rest of the code.

Which browser are you using that gives you this behavior? Have you tried other browsers?

At my age I still learn something new every day, but I forget two others.
 
sure the website is here:
-Don't go off this page, the other pages are still being made, you could mess up the database.

-Go to the form at the bottom of the page. "Add a training"
-Change the number of specific workouts
-Fill it in
-When you submit I have a PHP script that does a print_r($GLOBALS), so if you go into source code view you will see all the information on the POST data and REQUEST data.
-PLEASE don't do anything to the site (When you submit the add a training form it doesn't do anything, just displays all the registered GLOBALS) -- I don't want the database messed up and I would have to change my password to stop the url above from reaching it.
 
You should really have a test database so you run no risk of corrupting the main database. Even when you are the only one with access it is easy to make a mistake or to have an error in the code cause a hiccup that could cause you major headaches.

I found in your code that when you create the new fields you are giving them all the same name. They should really be named sequentially to keep things simpler so each new field should probably have a number appended to the name.

In PHP are you trying to access your fields as an array to get each value for each same named field?


At my age I still learn something new every day, but I forget two others.
 
Yes, they are put into arrays (or they should be). I'll look into it, but I don't think thats the problem.
 
Ok it turns out that BillyRayPreachersSon was right. I was certain I had the form around the table but when I check I found that, though it was around the table, it was between to trs, so I moved it to the very beginning of the table in which the table that was being modied was nested into, and voila! it works. Thanks to everyone who helped me out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top