August 1st, 2011, 01:49 PM
How to get values from dynamically created textbox to save in db
Hi Guys i am creating dynamic text boxes and i want to store their values into db,.
any help will be apreciated ..
code of a quick example of dynamic generated textbox is below:
//element with NO id
// newFieldElementNoId = document.createElement( 'INPUT' );
// newFieldElementNoId.onblur = show;
//element with id
for ( i=0;i<5;i++)
newFieldElement = document.createElement( 'INPUT' );
newFieldElement.onblur = show;
alert( 'id=' + this.getAttribute('id') + "\n" + 'name=' + this.getAttribute('name') + "\n" + "value=" + this.value );
August 1st, 2011, 02:05 PM
One option is to pass a hidden form field that you update to specify the number of dynamic fields (i.e. "3"). When you submit the form, you know there are 3 fields so you can loop from 1 to 3 (or whatever number you pass as the total count) and reference each of them by name and number.
You can also use form.fieldList to get a list of all the form fields that were submitted, and determine how many dynamic fields there are that way.
Or, you can use something like my Form Utilities CFC which lets you name the fields with an array syntax (i.e. "myField" and have CF automatically convert it into an array that you can then loop over.