auto generated field in php and stored into database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • azai lestary
    New Member
    • May 2013
    • 1

    auto generated field in php and stored into database

    I need you help please....

    first I want to create a page for php.. Inside it, I can add a number in a textfield... Then, textfield for 'name' will be generated based on that number...

    for example, i enter number =3; then 3 textfield will generated to fill the name.. and all the 3 name will stored into a table in database called 'names'

    here is simple code :

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function varifyInput()
    {
            var bb = document.getElementById('aa').value;
            var i = 0;
            var html = ''; 
    
            for (i=1;i<=bb;i++) {
            document.getElementById('aaa').innerHTML += "Name : <input type='text' value='' /><br />";
    }}
    </script>
    
    </head>
    <body>
    <form id="form1" name="form1" method="post" action="">
     <label>
      Number 
      <input type="text" name="aa" id="aa" />
      </label>
    <input type="submit" name="submit" id="submit" onClick="varifyInput()" value="Submit"     />
     <div id="aaa">
    
      </div>
    </form>
    </body>
    </html>
    Last edited by Rabbit; May 28 '13, 08:52 PM. Reason: Please use code tags when posting code.
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    azai lestary,

    You have the basic idea down; from here, the simplest thing to do is have a separate PHP page to process the result, when the "submit" button is pressed. The one thing you didn't do was to assign names the inputs that you generate.

    In the processing page, you have the count of inputs available - "aa" - and from that you can loop around all of the "Name" input fields. For your first pass, I suggest that you simply display the values recieved.

    Once you know that you are recieving data correctly, then you can create your database interface, and insert the records.

    Hopefully this lets you make progress.

    Cheers,
    Oralloy

    Comment

    Working...