Wednesday, 4 October 2017

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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...