I have a search button on body. On this search button click i am calling the button click event as:
$(document).ready(function() {
//On Search Button click, this function creates dynamic tables.
$("#searchBtn").click(function() {
var numArray = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
var alphaArray = new Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j");
var table = $('<table></table>').addClass('table');
for (i = 0; i < numArray.length; i++) {
var tbody = $('<tbody></tbody>');
var row = $('<tr></tr>');
var num = numArray[i];
var alpha = alphaArray[i];
row.on("click", function() {
selectRow(num, alpha);
});
var cell1 = $('<td></td>').addClass('spacer').text(numArray[i]);
var cell2 = $('<td></td>');
var button;
if (alpha[i] == "b") {
button = $('<button type="button">').addClass('btn btn-primary').text('BOY');
} else if (alpha[i] == "g") {
button = $('<button type="button">').addClass('btn btn-success').text('GIRL');
} else if (alpha[i] == "h") {
button = $('<button type="button">').addClass('btn btn-warning').text('HI');
}
cell2.append(button);
row.append(cell1);
row.append(cell2);
tbody.append(row);
table.append(tbody);
}
$('#searchTable').append(table);
});
Now on individual row click i am calling a function selectRow(num,alpha) which expects two paramters as:
function selectRow(num,alpha){
$(document).ready(function() {
alert("Number and Alphabet is "+num + alpha );
});
But when the control comes to the above function the alert always prints the last record of both the array.
What am i doing wrong? Looking forward to your answers.
$(document).ready(function() {fromselectRowfunction. You don't need that there.