0

I have multiple rows and with text box and button, I created a jQuery function to get the value of Text-box on class click. I tried so long but unable to get value. what I am doing wrong here.? Thanks in Advance. Text-box Code:-

$('input.R_Insert').click(function() {

  var roundNum = 0; // row no get from db (1,2,3,4,5..)

  var bb = "#TextBox" + roundNum;
  var x = $("bb").val();
  alert(x);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tbody>
  <tr>
    <td>
      <div id="">
        <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" CssClass="form-control" Rows="5" Text="" Enabled="false"></asp:TextBox>
        <asp:Button ID="btnSubmit1" runat="server" Text="Submit" CssClass="add_top_10 R_Insert" Enabled="false" />
      </div>
    </td>
    <td>
      <div id="">
        <asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" CssClass="form-control" Rows="5" Enabled="false"></asp:TextBox>
        <asp:Button ID="btnSubmit2" runat="server" Text="Submit" CssClass="add_top_10 R_Insert" Enabled="false" />
      </div>
    </td>
  </tr>
  <tr>
    <td>
      <div id="">
        <asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" CssClass="form-control" Rows="5" Text="" Enabled="false"></asp:TextBox>
        <asp:Button ID="btnSubmit3" runat="server" Text="Submit" CssClass="add_top_10 R_Insert" Enabled="false" />
      </div>
    </td>
    <td>
      <div id="">
        <asp:TextBox ID="TextBox4" runat="server" TextMode="MultiLine" CssClass="form-control" Rows="5" Enabled="false"></asp:TextBox>
        <asp:Button ID="btnSubmit4" runat="server" Text="Submit" CssClass="add_top_10 R_Insert" Enabled="false" />
      </div>
    </td>
  </tr>
</tbody>

2
  • Does the #Textbox0 element exist in your HTML? If so, where is it? Also note the selector should be $(bb), not $('bb') - note the lack of quotes as you're providing a variable, not a string literal Commented Jul 14, 2017 at 11:12
  • No ,` '#Textbox0` element does not exist. and I have tried $('bb') also but failed. Commented Jul 14, 2017 at 11:19

3 Answers 3

1

just remove the double quotes-

var bb = "#TextBox" + roundNum;
            var x = $(bb).val();
Sign up to request clarification or add additional context in comments.

Comments

0

You can also try this one that work with textbox,dropdown, textarea.

$('.R_Insert').click(function () {
  //This will work for textarea,input, select controls
  var x = $(this).parent().find('.form-control').val();         
  alert(x);
});

Comments

0

Here is a working code. You may play @ https://jsfiddle.net/wmfn5t7c/

<table>

<tbody>
                    <tr>
                        <td>
                            <div id="">
                                <input type='TextBox' ID="TextBox1" runat="server" TextMode="MultiLine" CssClass="form-control" Rows="5" Text="" Enabled="false" />
                                <input type='Button' ID="btnSubmit1" runat="server"  Text="Submit" CssClass="add_top_10 R_Insert" Enabled="false" />
                            </div>
                        </td>
                        <td>
                            <div id="">
                                <asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" CssClass="form-control" Rows="5" Enabled="false"></asp:TextBox>
                                <asp:Button ID="btnSubmit2" runat="server" Text="Submit" CssClass="add_top_10 R_Insert" Enabled="false" />
                            </div>
                        </td>
                    </tr>
                 <tr>
                        <td>
                            <div id="">
                                <asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" CssClass="form-control" Rows="5" Text="" Enabled="false"></asp:TextBox>
                                <asp:Button ID="btnSubmit3" runat="server" Text="Submit" CssClass="add_top_10 R_Insert" Enabled="false" />
                            </div>
                        </td>
                        <td>
                            <div id="">
                                <asp:TextBox ID="TextBox4" runat="server" TextMode="MultiLine" CssClass="form-control" Rows="5" Enabled="false"></asp:TextBox>
                                <asp:Button ID="btnSubmit4" runat="server" Text="Submit" CssClass="add_top_10 R_Insert" Enabled="false" />
                            </div>
                        </td>
                    </tr>
                </tbody>
</table>

 $('#btnSubmit1').click(function () {

            var roundNum = 1; // row no get from db (1,2,3,4,5..)

            var bb = "#TextBox" + roundNum;
            var x = $(bb).val();
            alert(x); 
            });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.