SUNNY99
05-11-2009, 07:23 PM
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 with ASP
Say user chooses 3 names to add. (3 text boxes display)
How do I dynamically create these 3 fields in access database using ASP?
How do i then insert these values into these 3 new fields?
Thanks for ur help
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>
***********************
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 with ASP
Say user chooses 3 names to add. (3 text boxes display)
How do I dynamically create these 3 fields in access database using ASP?
How do i then insert these values into these 3 new fields?
Thanks for ur help
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>
***********************