Adding Dynamic Form Fields to Access Database using ASP

Discussion in 'C#' started by sunny99, May 10, 2009.

  1. #1
    Adding Dynamic Form Fields to Access Database using ASP

    I am trying to create a form with dynamic form Fields.

    I have set up javascript to dynamically display number of Text fields based on drop down selection.

    When the submit button is hit it should run asp script file to add the field data into a MS access database.

    I have uploaded the html file at following site.

    www12.asphost4free.com/sunny99/Test.html

    I will appreciate if anyone can help me doing this.

    HTML CODE for the file is listed below

    ***********************


    <html>
    <head>
    <title>untitled</title>
    <style type="text/css">

    div.inputbox {
    width: 200px;
    font-size: 80%;
    padding: 3px 0px 3px 50px;
    }

    </style>


    <script type="text/javascript" language="javascript">

    function setTextInputs(oSelect) {
    var howmany = oSelect[oSelect.selectedIndex].value, add = true;
    var n = 1, oForm = oSelect.form, oDiv, oInput;
    while (oDiv = document.getElementById('Name' + n))
    if (n++ > howmany) {
    add = false;
    oForm.removeChild(oDiv);
    }
    if (add)
    for (n; n <= howmany; ++n) {
    oDiv = document.createElement('div');
    oDiv.setAttribute('id', 'Name' + n);
    oDiv.className = 'inputbox';
    oDiv.appendChild(document.createTextNode('Name ' + n + ': '));
    oForm.appendChild(oDiv);

    oInput = document.createElement('input');
    oInput.setAttribute('type', 'text');
    oInput.setAttribute('name', 'Name' + n);
    oDiv.appendChild(oInput);
    }
    }

    </script>
    </head>
    <body>
    <form>
    <p><strong>Number of People: </strong>
    <select name="NoOfPpl" onChange="setTextInputs(this)">
    <option value="0" selected="selected">- 0 -</option>
    <option value="1">- 1 -</option>
    <option value="2">- 2 -</option>
    <option value="3">- 3 -</option>
    <option value="4">- 4 -</option>
    <option value="5">- 5 -</option>
    <option value="6">- 6 -</option>
    <option value="7">- 7 -</option>
    <option value="10">- 10 -</option>
    </select></p>
    </form>
    <label>
    <input type="submit" name="Submit" value="Submit">
    </label>
    </body>
    </html>

    ***********************
     
    sunny99, May 10, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Do you have any ASP experience? What is the purpose of the form?
     
    camjohnson95, May 10, 2009 IP