locked
How to send dynamically created input fields values to database RRS feed

  • Question

  • User-1557173817 posted

    Hello, i used javascript to dynamically create input fields but cant sends values to database (using webmatrix)

    Monday, August 31, 2015 7:23 AM

Answers

  • User1313602441 posted
    The most JavaScript can do for you here is to validate the inputs, which you shouldn't always trust either. It can't send them to the database.

    Plus, the html form needs to have an attribute called "action" to direct it to where the inputs can be processed on the server.
    To actually get and insert the user generated inputs, you need to use the Asp.net "Request" object, similar to how you did it with JavaScript.


    I recommend you go through the WebPages tutorial on www.asp.net for more understanding of these basics.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2015 11:18 AM

All replies

  • User325035487 posted

    Cant help you unless you post what you did so far

    Monday, August 31, 2015 7:25 AM
  • User-1557173817 posted

    html:

    <label for="invoiceE"> Invoice Entry</label>
                         <input class="form-control" type="text" name="invoiceE" placeholder="Description" value="@Request.Form["invoiceE"]" />
                         <p class="help-block"> @Html.ValidationMessage("damount")</p>
                       
                        
                         <input class="form-control" width="20px" type="text" name="amount" placeholder="Amount" value="@Request.Form["amount"]" />
                         <p class="help-block"> @Html.ValidationMessage("amount")</p>
         </div>
       <p>  <input type="button" value="Add another Entry" onClick="addInput('dynamicInput');"></p>
    
    javascript:
      <script>
       var counter = 1;
    var limit = 20;
    function addInput(divName){
         if (counter == limit)  {
              alert("You have reached the limit of adding " + counter + " inputs");
         }
         else {
              var newdiv = document.createElement('div').cloneNode(true);
              newdiv.innerHTML = "Invoice Entry " + (counter + 1) + " <br><input type='text' class='form-control' value='@Request.Form["invoiceE"]' placeholder='Description' name='invoiceE[]'>" + " <br><input type='text' class='form-control' placeholder='Amount' value='@Request.Form["amount"]' name='amount[]'>";
              document.getElementById(divName).appendChild(newdiv);
              counter++;
         }
    }
     
    </script>

    The problem is that the input that was generated with javascript code is not sending the values to the database
    Monday, August 31, 2015 7:53 AM
  • User-1557173817 posted

    what will do to send the values to DB

    Wednesday, September 9, 2015 12:23 PM
  • User1633621018 posted

    Hi Dan,

    Where is your code for fetching the input values? You have provided cod for creating inputs only. Post that too.

    Wednesday, September 9, 2015 12:28 PM
  • User-1980594115 posted

    Do you have a submit button? Is the form directing the values to another page or to the same page.  Place the following toward the top of the page that the form is sending the data to:

    @ObjectInfo.Print(Request.QueryString) <br />
    @ObjectInfo.Print(Request.Form) <br />
    @ObjectInfo.Print(Request.Url) <br />
    

    The above will display the variables that is being received from the form either as a GET or PUT method. Then you can place these fields data into the database.

    Wednesday, September 9, 2015 1:50 PM
  • User-1557173817 posted

    Hello my code for requesting the values are there, within the javascript code (@Request.form["Amount"]).....

    Thursday, September 10, 2015 7:13 AM
  • User1313602441 posted
    The most JavaScript can do for you here is to validate the inputs, which you shouldn't always trust either. It can't send them to the database.

    Plus, the html form needs to have an attribute called "action" to direct it to where the inputs can be processed on the server.
    To actually get and insert the user generated inputs, you need to use the Asp.net "Request" object, similar to how you did it with JavaScript.


    I recommend you go through the WebPages tutorial on www.asp.net for more understanding of these basics.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 10, 2015 11:18 AM