Link to home
Create AccountLog in
Avatar of Member_2_5230414
Member_2_5230414

asked on

return values from java script created textbox to add to sql database.

Hello,

I have a form which works great.
http://jarrattperkins.com/training/addtraining.aspx

Open in new window


But I set the textboxes via javascript

$(document).ready(function () {

    var counter = 2;

    $(".addButton").on("click", function () {
     


        var newTextBoxDiv = $(document.createElement('div'))
      .attr("id", 'TextBoxDiv' + counter);

        newTextBoxDiv.html(' <label class="alignme" for="repdist' + counter + '">Rep' + counter + ' - </label><label for="repdist' + counter + '">Distance:</label>' +
    ' <input  onkeypress="return IsNumber(event)"  name="repdist' + counter + '" type="text" id="repsit' + counter + '" style="width:30px;" />' +
   '  <select name="kmormile' + counter + '" id="kmormile' + counter + '"> ' +
     	'<option value="Miles">Miles</option>' +
        	'<option value="Km">Km</option>' +
           ' </select>' +
                      ' <label for="repmin' + counter + '">Min:</label>' +
                   '  <input onkeypress="return IsNumber(event)"  name="repmin' + counter + '" type="text" value="00" maxlength="2" id="repmin' + counter + '" style="width:30px;" />' +

                      ' <label for="repsec' + counter + '">Sec:</label>' +
                     '<input onkeypress="return IsNumber(event)"  name="repsec' + counter + '" type="text" value="00" maxlength="2" id="repsec' + counter + '" style="width:30px;" />');

        newTextBoxDiv.appendTo("#TextBoxesGroup");


        counter++;
    });

    $(".removeButton").on("click", function () {
        if (counter == 1) {
            alert("No more textbox to remove");
            return false;
        }

        counter--;
  
        $("#TextBoxDiv" + counter).remove();

    });

  
    $("#getButtonValue").click(function () {

        var msg = '';
        for (i = 1; i < counter; i++) {
            msg += "\n Textbox #" + i + " : " + $('#textbox' + i).val();
        }
        alert(msg);
    });
});

Open in new window


How can i return the values to add into sql db???
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Member_2_5230414
Member_2_5230414

ASKER

how would i get the varrepmin and stick it into a sql query though??
u probably need to pass the values to your code-behind where you update your DB.
so basically u need to right some web service and use ajax (for example) to pass whatever u need from your client side to your server in order to update the DB.
in your DB add stored procedure which updates the table or create sql query and run it.