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
$(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()