Check if the checkbox is checked or not.

As per my previos post, what I did was get all the categories, now I wanted to change the categories checkbox status using ajax. For this I had to get the category ID and the checkbox status using javascript.

My previous Code

@foreach($categories as $category)
   
            <input class="checkbox_id" type="checkbox" id="{{$category->category_id}}" value="{{$category->category_id}}"
           {{isset($selectedCategories) ? (in_array($cateogry->category_id, array_values($selectedCategories->categories->pluck('fk_category_id')->toArray())) ? 'checked' : '') : ''}}>
              
            <label for="{{$category->category_id}}">
                {{$category->category_name}}
            </label>
@endforeach
 $('body').delegate('.checkbox_id', 'click', function () {
          
           var category_id = $(this).data('id');
            if ($(this).is(':checked')) {
                var check_status = 1;
            }
            else {
                var check_status = 0;
            }
            var data = { 'id': category_id, 'check_status': check_status };
            updateCategorty(data)
        });

function updateCategorty(data) {
            $.ajax({
                url: '{!! route('updateCategory') !!}',
                type: 'POST',
                data: data,
                success: function (data, textStatus, jqXHR) {
                    if (data.status == 200) {
                        toastr.success(data.message);
                    }
                    else {
                        toastr.warning(data.message);
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    toastr.warning("Server error. Please try again later");
                }
            });
        }

What we are doing here is checking if the input class with ‘checkbox_id’ is changed or not. If it is changed, then the next if statement will check if it is checked, and if its true then the ‘check_status’ variable will get the value to be 1 else the value will be 0.

All of the variables are assiged to the variable ‘data’. Then I have called the function updateCategory(data) where all the ajax call is done. The data is routed to the give route where the controller does the rest of the job.

I hope this helps.

12 thoughts on “Check if the checkbox is checked or not.”

  1. Excellent website. Plenty of helpful information here.
    I am sending it to several buddies ans additionally sharing in delicious.
    And certainly, thank you in your sweat!

  2. I have recently started a site, the info you offer on this site has helped me tremendously. Thanks for all of your time & work. “Men must be taught as if you taught them not, And things unknown proposed as things forgot.” by Alexander Pope.

  3. Monitor Closely 1 glecaprevir pibrentasvir will increase the level or effect of maraviroc by P glycoprotein MDR1 efflux transporter buy priligy online safe Safety and effectiveness of Diovan in patients with severe renal impairment CrCl 30 mL min have not been established

  4. equilibrado de turbinas
    Equipos de balanceo: importante para el funcionamiento estable y productivo de las equipos.

    En el ámbito de la tecnología actual, donde la productividad y la estabilidad del aparato son de alta significancia, los sistemas de balanceo desempeñan un papel esencial. Estos equipos especializados están diseñados para ajustar y regular piezas móviles, ya sea en dispositivos industrial, vehículos de traslado o incluso en aparatos domésticos.

    Para los expertos en mantenimiento de sistemas y los especialistas, operar con dispositivos de balanceo es esencial para garantizar el desempeño fluido y estable de cualquier sistema rotativo. Gracias a estas soluciones modernas modernas, es posible disminuir notablemente las sacudidas, el sonido y la carga sobre los cojinetes, extendiendo la longevidad de piezas costosos.

    Asimismo trascendental es el rol que desempeñan los aparatos de calibración en la asistencia al cliente. El asistencia especializado y el mantenimiento regular empleando estos equipos facilitan dar servicios de excelente excelencia, aumentando la contento de los usuarios.

    Para los responsables de negocios, la financiamiento en unidades de balanceo y medidores puede ser clave para mejorar la rendimiento y rendimiento de sus aparatos. Esto es sobre todo importante para los empresarios que administran pequeñas y intermedias organizaciones, donde cada detalle es relevante.

    También, los equipos de equilibrado tienen una gran aplicación en el área de la seguridad y el monitoreo de excelencia. Facilitan encontrar posibles problemas, impidiendo intervenciones caras y problemas a los sistemas. Además, los resultados recopilados de estos aparatos pueden aplicarse para optimizar procedimientos y potenciar la visibilidad en buscadores de exploración.

    Las campos de uso de los dispositivos de balanceo abarcan diversas áreas, desde la manufactura de bicicletas hasta el control ecológico. No afecta si se habla de importantes producciones productivas o limitados establecimientos domésticos, los equipos de equilibrado son indispensables para proteger un operación productivo y sin interrupciones.

  5. 德州撲克規則
    你是不是也想學德州撲克,卻被一堆術語搞得霧煞煞?別擔心,這篇就是為你準備的「規則懶人包」,從發牌、下注到比牌,5 個階段、5 種行動,一次搞懂!德州撲克新手必看!快速掌握德撲規則與下注方式,從發牌、翻牌到比牌,一次看懂德州撲克 5 大階段與 5 種行動,不再上桌搞不懂規則。

  6. 德州撲克規則
    想學德州撲克卻完全沒頭緒?不管你是零基礎還是想重新複習,這篇就是為你準備的!一次搞懂德州撲克規則、牌型大小、下注流程與常見術語,讓你從看不懂到能開打一局只差這一篇!看完這篇,是不是對德州撲克整個比較有頭緒了?從玩法、流程到那些常聽不懂的術語,現在是不是都懂了七八成?準備好了嗎?快記好牌型、搞懂位置,然後開打一局練練手啦!富遊娛樂城提供最新線上德州撲克供玩家遊玩!首家引進OFC大菠蘿撲克、NLH無限注德州撲克玩法,上桌就開打,數錢數不停!

Leave a Comment

Your email address will not be published. Required fields are marked *

Tweet
Share
Share
Pin