PDA

View Full Version : How to get dynamically generated form fields to post?


shokora
03-20-2008, 10:54 PM
I'm relatively new to JS, and I got thrown a project where I'm basically trying to learn now to write it on the fly.

The problem: My company has a form on the local intranet that allows users to input some information (duh) and gives them the option to add additional steps as necessary. The issue is that these additional steps are not single input fields. The "Add another step" button outputs a large table that has somewhere along the lines of 15+ input fields.

There are plenty of tutorials out there on how to add a single input box (like this (http://binnyva.blogspot.com/2006/01/dynamic-form-field-generation-in.html)), but those just don't help me due to the scale of this assignment.

Right now, I am inserting the HTML steps dynamically from the JS function based on a step number counter. The insert includes the entire table, input fields and all. It's being placed into the HTML with innerHTML, and it works. [Clarification: I'm appending the new steps into a placeholder div with innerHTML.]

However, I'm having issues getting the values from the dynamically generated fields to post so that my PHP can access it and update the database accordingly.

I'm sorry that I can't post any snippets of the code, due to NDA requirements, so I hope I was detailed enough in explaining. Any help would be great!

_Aerospace_Eng_
03-20-2008, 11:00 PM
So why don't they hire someone who knows what they are doing? Either way what seems to be happening is the script uses innerHTML to create the massive table. Form elements that are created using innerHTML aren't part of the dom. To make dynamically generated form elements part of the dom you need to use DOM methods such as createElement and appendChild. With that said, good luck.

shokora
03-20-2008, 11:13 PM
Thanks for the tip, that should help plenty... but I appreciate it if you lay off on the sarcasm next time. It'd be wonderful to just "hire someone who knows what they are doing" whenever I get stuck on a problem, but alas, the world doesn't always work that way. I came here looking for some support. That IS the point of this forum right?