Tuesday 27 September 2016

php - Want to get all values of checked checkbox using jquery



How can I get multiple checkbox values in a variable as it is showing only the last checked value on alert? I am beginner in jquery ,any help will be appreciated.



My working link is :



link




//HTML



























































Time Monday tuesday Wednesday Thursday Friday Saturday Sunday
9-11 select select select select select select select
11-1 select select select select select select select
1-2 select select select select select select select
2-3 select select select select select select select




//jQuery Code



$(function(){

$('input:not(#submit)').click(function()
{
t= $(this).attr('class');


text= $('.time'+t).text();
//alert(text);




});

// For getting the Day
$('td').click(function()
{
index = this.cellIndex;


days = $('tr:first').find('td').eq(index).text();


// alert(days);
});

// for saving data into the database
$('#submit').click(function() {
alert(text);
alert(days);


/* $.ajax({

type: "POST",
cache: false,
url: 'save.php',
data: {'time='+time, 'day='+day},
success: function(data) {
alert('data has been stored to database');
}
}); */
});


});

Answer



Try,



var trs = $('table tr');
var values = trs.first().find('td');

var values1 = $('table tr td :checkbox:checked').map(function () {
return $(this).closest('tr').find('th').text() + "==>"

+ values.eq($(this).parent().index()).text();
}).get();



No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...