Welcome Guest, Not a member yet? Register   Sign In
checkbox value for Edit not showing as checkbox checked
#2

(This post was last modified: 08-04-2022, 05:59 AM by Ahmed Haroon.)

added these lines in below code but it is showing "checked" first time going to Edit, then on every attempt it is showing it unchecked no matter it is "Y"
please help.
                if($('#product_available').val() == 'Y') {
                    $('#product_available').attr('checked', true);
                }else{
                    $('#product_available').attr('checked', false);
                }



       
PHP Code:
// to fill data in Edit mode
        var subcategorygobal '';
        $(document).ready(function(){

            // get Edit Product
            $('.btn-edit').on('click',function(){
                // get data for Editing a selected row
                const id = $(this).data('id');
                const name = $(this).data('name');
                const price = $(this).data('price');
                const category = $(this).data('category_id');
                const subcategory = $(this).data('subcategory_id');
                const product_available = $(this).data('product_available');
                // Set data to Form Edit
                $('.product_id').val(id);
                $('.product_name').val(name);
                $('.product_price').val(price);
                $('.product_category').val(category).trigger('change');
                $('.checkboxitem').val(product_available);
// start: code added here...
                if($('#product_available').val() == 'Y') {
                    $('#product_available').attr('checked'true);
                }else{
                    $('#product_available').attr('checked'false);
                }
// end: code added here...
                subcategorygobal subcategory;
                // Call Modal Edit
                $('#dmlModal').modal('show');
        }); 

regards
Newbie here in CodeIgniter World !! Please appologize if any nonsense from me.  
environment: Windows 10, XAMPP 3.3.0, VS Code, SQLyog Community Ed. 
Reply


Messages In This Thread
RE: checkbox value for Edit not showing as checkbox checked - by Ahmed Haroon - 08-04-2022, 05:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB