...

View Full Version : Dynamically add textbox for user entry and saving data entered



chrscote
05-05-2009, 07:14 PM
I have an ASP page that displays, along with other data, a list of items that refer to a specific element in a database. Instead of adding an Add button, I would like to display a text box below the last item in the list to have the user input any new data. Once they enter the data and hit Enter, the data they enter should then be added to the list and another text box added beneath this item (just as forms and tables in Access do).
However, I'm not sure how to implement this functionality. Can someone please help me out?

Chris

Philip M
05-05-2009, 07:54 PM
Try this:-



<input type="hidden" value="0" id="theValue" />
<div id="myDiv"> </div>

<script type = "text/javascript">

function addElement() {
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById('theValue').value -1)+ 2;
numi.value = num;
var newdiv = document.createElement('div');
var divIdName = 'my'+num+'Div';
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = "Item " + num + " " + "<input type='text' size = '60' name='poll_option+num' onblur = 'capture(this)'/>"
ni.appendChild(newdiv);
}

function capture(which) {
x = which.value;
alert (x); // add data to an array or whatever
}

</script>

<input type = "button" name = "but1" id = "but1" value = "Add Some More Data" onclick = "addElement()">

Or if you want to dispense with the button:-

<body onload = "addElement()">

newdiv.innerHTML = "Item " + num + " " + "<input type='text' size = '60' name='poll_option+num' onblur = 'capture(this);addElement()'/>"

"He has been in the final of the tournament before, and people often go on from there to win it ...." Snooker commentator.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum