Monday, January 28, 2019

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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...