1

I have built the following Gridview (Employees and their weekly target):

Gridview of consultants and their targets

Desired result: I have a submit button at the bottom which will take all the data from the Gridview using jQuery and push it into my database.

At the moment, I cannot even retrieve the textbox values though, i have the following code:

$(document).ready(function () {

        $("#btnSubmit").click(function () {
                $("#GridView1 td").each(function () {

                var value = $(this).text();
                alert(value);
                });
        });
});

This Selects all the "Table Data" cells... It is selecting the names perfectly, but as soon as it gets to a textbox, it doesnt get the value I type in, it just alerts nothing.

I have tried the following too, each with different, but not the desired results:

.html
.val
.innerHTML

Would anyone be able to point out where I am going wrong please? please let me know if you need anymore info...

1
  • You have to check for the controls in the table cells! Commented Mar 13, 2014 at 11:27

2 Answers 2

2

You have to check if the control exists in the table cells or not
Give this a try

var value = $(this).find('input').length > 0 ? $(this).find('input').val() : $(this).text();

Hope this will work!

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

1 Comment

@Mike Glad to hear it! Welcome :)
0

You must select the input textbox in your selection as given below

$(document).ready(function () {
    $("#btnSubmit").click(function () {
        $("#GridView1 td input").each(function () {

            var value = $(this).val();
            alert(value);
        });
    });
});

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.