0

I am trying to retrieve a specific value from a table created at runtime in the code behind. using jquery.

sb.Append("<tr><td>");
                sb.Append(prodCode);
                sb.Append("</td>");


                sb.Append("<td>");
                sb.Append("<input type='checkbox' name='chkBestSeller' value='Best Seller' style='font-size:x-small;'");
                sb.Append("<input type='hidden' name='prodCodeBestSeller' value='" + prodCode + "'");
                sb.Append("</td>");
Products.InnerHtml = sb.ToString();

this is my jquery function.

$(document).on("click", "input[name='chkBestSeller']", function () {
var code = $(this).parent().find("input[name='prodCodeBestSeller']").val();
alert(code);

});

My feeling is that it should work but it brings back a value of 'undefined' instead.

How can i achieve retrieving the code value at the specific row

1
  • 2
    you are not closing your input's with > .... Jul 2, 2013 at 12:29

2 Answers 2

2

try this

$("input[name='chkBestSeller']").click( function () {
var code = $(this).closest('tr').find("input[name='prodCodeBestSeller']").val();
alert(code);
});
1
$(document).on("click", "input[name='chkBestSeller']" ...

this refers to the element clicked on, i.e. input[name='chkBestSeller'].

In your case you can get the value of the hidden field with

$(this).next().val()

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.