samedi 5 mars 2016

I need to change my sucess when my checkbox get unchecked

Here is my code:

 $(document).ready(function()
            {
              $( ".iCheck-helper" ).on( "click", function(){

                    var sel = $('.i-check:checked').map(function(_, el) {
                        // if($(this).is(":checked")){
                                return $(el).val();
                            }
                        }).get();
                        // alert(sel);

                    var nme = $('.i-check:checked').map(function() {
                            // return $(el).val();
                            return $(this).attr("name");
                        }).get();
                      // alert(nme);

                      var value = this.value;
                      // this(attir)
                      var city_name =<?php echo json_encode($cityname) ?>;
                      var start =<?php echo json_encode($start)?>;
                      var end =<?php echo json_encode($end)?>;
                      var room_count =<?php echo json_encode($room_count)?>;
                      var member_count =<?php echo json_encode($member_count)?>;
                      var selt_guest =<?php echo json_encode($selt_guest)?>;
                      var selt_room =<?php echo json_encode($selt_room)?>;
                      // alert(city_name);
                      $.ajax({
                        // alert();
                        type: "POST",
                        url: "hotelresults",
                        data: {
                            key : sel,
                            name:nme,
                            search_city:city_name,
                            start:start,
                            end:end,
                            selt_guest:selt_guest,
                            selt_room:selt_room,
                            room_nf:room_count,
                            guest_nf:member_count,

                        },
                        success: function (data) {
                            $('.hotel_list').html(data);
                        }
                    });

              });
            });

While clicking a checkbox this success function calls.And here sel & name are passed into the controller as in array manner

If one of my checkbox is unchecked it should pass the remaining values of the array in both sel and name.

And if all the checkboxes are unchecked my sel & name value set to null.

So here,when my values get null or all checkboxes are set unchecked I need to pass another set of data in my Success like as follows

data: {
       search_city:city_name,
       start:start,
       end:end,
       selt_guest:selt_guest,
       selt_room:selt_room,
       room_nf:room_count,
       guest_nf:member_count,                                
       }

Please someone help mee...

And Here, I need that .map function as must because without that function my values didn't pass to the controller.




Aucun commentaire:

Enregistrer un commentaire