Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2003
    Location
    Jewett City, CT
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Dynamically add textbox for user entry and saving data entered

    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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Try this:-

    Code:
    <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.
    Last edited by Philip M; 05-05-2009 at 07:58 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •