#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    60
    Rep Power
    4

    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 ..

    thanks

    code of a quick example of dynamic generated textbox is below:

    [code]
    <html>
    <head>
    <script language="javascript">
    function init()
    {
    //element with NO id
    // newFieldElementNoId = document.createElement( 'INPUT' );
    // newFieldElementNoId.onblur = show;
    // document.body.appendChild(newFieldElementNoId);

    //element with id
    var i;
    for ( i=0;i<5;i++)
    {
    newFieldElement = document.createElement( 'INPUT' );
    newFieldElement.setAttribute('id','myfieldid'+i);
    newFieldElement.setAttribute('name','myfieldname'+i);
    newFieldElement.onblur = show;
    document.body.appendChild(newFieldElement);
    }
    }
    function show(){

    alert( 'id=' + this.getAttribute('id') + "\n" + 'name=' + this.getAttribute('name') + "\n" + "value=" + this.value );
    }
    </script>
    </head>
    <body onload="init()">
    </body>
    </html>
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,264
    Rep Power
    968
    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[3]" and have CF automatically convert it into an array that you can then loop over.

IMN logo majestic logo threadwatch logo seochat tools logo