Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have use this script to generate a textboxes dynamically .how can i get a dynamically textboxes values and save in to database .

XML
<table>


                   <tr>

                       <td>
                                <label class="lbl_sm" style="font-size: 0.75em" for="adults">Adults</label>
                       </td>

                       <td>

                             <a href="#" onclick="doIt(-1); return false;">-</a>
       <input type="text" value="2" id="txtBox" class="text-box"  />
    <a href="#" onclick="doIt(1); return false;">+</a>

                       </td>
                       <td>
                           <label class="lbl_sm" style="font-size: .75em;" for="children">Children</label>
                       </td>

                       <td>

<a href="#" onclick="doItChild(-1); return false;">-</a>
       <input type="text" value="0" id="txtChld"  class="text-box" />
    <a href="#" onclick="doItChild(1); return false;">+</a>
                       </td>
                   </tr>
                   <tr>
                       <td  colspan="4"> <span style="font:normal 12px agency, arial; color:blue; text-decoration:underline; cursor:pointer;" onclick="addMoreRows(this.form);"> Add Room </span>
                      </td>
                          <%-- <td>
                       </td>
                       <td>
                       </td>
                       <td>
                       </td>
                       <td>
                       </td>--%>
                   </tr>
                   <tr>
                        <td>
                       </td>
                       <td>
                       </td>
                   </tr>
               </table>
           </div>
                </asp:Panel>
         <div id="addedRows"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
   <script type="text/javascript"> var rowCount = 1; function addMoreRows(frm) { rowCount++; var recRow = '<p id="rowCount' + rowCount + '"><tr> <td style="font-size:14px;" >Adult</td> </tr> <tr><td>  <a href="#" onclick="doIt(-1); return false;">-</a> <input type="text" value="2" id="txtBox' + rowCount + '" class="text-box"  /> <a href="#" onclick="doIt(1); return false;">+</a></td> <tr> <td style="font-size:14px;" >Child</td> </tr><td><a href="#" onclick="doIt(-1); return false;">-</a>  <input type="text" value="0" id="txtChld' + rowCount + '" class="text-box"  /><a href="#" onclick="doIt(1); return false;">+</a></td></tr> <a href="javascript:void(0);" onclick="removeRow(' + rowCount + ');">Remove</a></p>'; jQuery('#addedRows').append(recRow); } function removeRow(removeNum) { jQuery('#rowCount' + removeNum).remove(); } </script>
Posted
Updated 1-Sep-15 20:34pm
v3
Comments
Maciej Los 2-Sep-15 2:32am    
What have you tried? Where are you stuck?
rajshekhar yadav 2-Sep-15 2:39am    
on click button i have write this function
<script type="text/javascript">

function GetTextBoxValueTwo() {
$(".text-box").each(function () {
alert($(this).val());

//var txt = $(this).val();
//lblTtlAdlts.Text = txt;
});


//$(this).find('lblTtlAdlts').each(function () {
// alert('label text:' + $(this).text());
//});
}

</script>
its so me a alert of text boxes values bt i want to this values display in label and then save in to data base

<asp:Button class="MyButton" ID="btnBook" runat="server" Text="ADD" OnClick="btnBook_Click" Width="126px" value="Click!" OnClientClick="GetTextBoxValueTwo()" />
rajshekhar yadav 2-Sep-15 3:08am    
how can i use this val object in server side?
F-ES Sitecore 4-Sep-15 7:23am    
You have to make sure the dynamically created input elements have unique "name" attributes, and in your server code you get the values like

Request.Form["input_name_goes_here"]

1 solution

If you want to get the values of the textboxes in server side, then add runat="server" property in the markup.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900