0

How to get the textbox value of all fields when a key is entered. Im able to get only first and last textbox value. I failed to get the middle textbox value.

        $("#GridView1 :text").live("keyup", recalculate);

function recalculate() {
                 $("#GridView1 tbody tr:first").each(function () {
                     var text = $(":text", this);
                     var First = Number.parseInvariant(text.first().val());
                     var Middle= Number.parseInvariant(text.first().next().val());
                     var Last= Number.parseInvariant(text.last().val());
                });
            }
2
  • instead of tr:first each , try :text each Commented Mar 14, 2020 at 8:43
  • Hello @Kurt 666, I have added snippet below, you can refer that,in case of still required anything else please let me know. Thank you!!! Commented Mar 14, 2020 at 12:47

2 Answers 2

1

Try this:

$('input[type="text"]').each(function(i){
    console.log($(this).val());
 });

you will get all text box values.

Sign up to request clarification or add additional context in comments.

Comments

0

I have made a sample example using the table with text boxes, so you can refer that snippet, might be it helps you.

$('input[type="text"]').keyup(function() {
  recalculate();
});

function recalculate() {
  $("#GridView1").find("tr").each(function(e, element) {
    var firstTextBox = $($(element).find('input[type="text"]')[0]).val();
    var secondTextBox = $($(element).find('input[type="text"]')[1]).val();
    var thirdTextBox = $($(element).find('input[type="text"]')[2]).val();
    console.log("Grid Row : " + (e + 1) + " txt1: " + firstTextBox + " txt2: " + secondTextBox + " txt3: " + thirdTextBox);
  });
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<table id="GridView1" cellpadding="0" cellspacing="0">
  <tbody>
    <tr>
      <td><input type="text" value=""></td>
      <td><input type="text" value=""></td>
      <td><input type="text" value=""></td>
    </tr>
    <tr>
      <td><input type="text" value=""></td>
      <td><input type="text" value=""></td>
      <td><input type="text" value=""></td>
    </tr>
    <tr>
      <td><input type="text" value=""></td>
      <td><input type="text" value=""></td>
      <td><input type="text" value=""></td>
    </tr>
  </tbody>
</table>

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.